some kinda mail() problem

Discussion in 'PHP' started by enchance, Sep 15, 2007.

  1. #1
    I made an email form "contact.php" which makes use of the code below in a separate php file "mail.php"
    but I just can't get it to work. I'm kinda new to php. ;D

    <?
    //assign the constants
    $agiemail = "email@agi.com";
    $aginame = "AGI";
    $inittxt = "WEB: ";
    
    //get the values
    $sender = $_POST['fName'];
    $subject = $_POST['fSubject'];
    $email = $_POST['fEmail'];
    $phone = $_POST['fPhone'];
    $msg = $_POST['fMessage'];
    $checkbox = $_POST['fCheckbox'];
    $date = date("l, F j, Y"); 
    $time = date("h:i A"); 
    
    //*****The error must be somewhere in the code below*****
    $header =
    		"To: " . $aginame . "<" . $agiemail . ">\n" .
    		"Subject: " . $inittext . $subject . "\n" .
    		"From: " . $sender . "<" . $email . ">\n" .
    		"X-Mailer: PHP 4.x";
    		
    $message = 
    		"\n**This message was sent from the AGI website**\n\n\n" .
    		"Sender: " . $sender . "<" . $email . ">\n" .
    		"Date: " $date . " " . $time . "\n" .
    		"Reply by phone: " . $checkbox . "\n" .
    		"Telephone: " . $phone . "\n\n" .
    		$subject . "\n" . $msg;
    		
    //send the mail + error messages
    if(mail($agiemail, $subject, $message, $header))
    {
    	 header('Location: sent.php');
    }
    else
    {
    	header('Location: emailnotsent.php');
    }
    ?>
    Code (markup):
    I keep getting the error message in my browser:

    Parse error: syntax error, unexpected T_VARIABLE in D:\xampp\htdocs\agi\_snippets\php\mail.php on line 25
    Code (markup):
    Can you guys tell me what I'm doing wrong? I'm running it on localhost using the latest version of xamp. This is my first time working on php.
     
    enchance, Sep 15, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You're missing a period in this line.
    
    "Date: ". $date . " " . $time . "\n" .
    
    PHP:
    (I added it in the code above)
     
    nico_swd, Sep 15, 2007 IP
  3. enchance

    enchance Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Oh, you're right! This post is so embarrassing! Thanks a lot man.
     
    enchance, Sep 15, 2007 IP
  4. enchance

    enchance Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I did what you said which kind of fixed it but now I'm getting another problem:

    New problem:
    
    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\xampp\htdocs\agi\_snippets\php\mail.php on line 31
    
    Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\agi\_snippets\php\mail.php:31) in D:\xampp\htdocs\agi\_snippets\php\mail.php on line 37 
    Code (markup):
    What could this be?
     
    enchance, Sep 15, 2007 IP
  5. azoundria

    azoundria Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Are you sure your host supports phpmail()? You should talk to them.
     
    azoundria, Sep 15, 2007 IP
  6. adrevol

    adrevol Active Member

    Messages:
    124
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #6
    try uploading it on to server and then do a test .. its problem with localhost SMTP ...
     
    adrevol, Sep 15, 2007 IP
    indianseo likes this.
  7. enchance

    enchance Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, thanks. I uploaded it and it worked! Thanks a lot people.
     
    enchance, Sep 16, 2007 IP