Sending Email with PHP

I am trying to send plain/text email to gmail using the following PHP code:

<?php
if(isset($_POST['email'])) {
				
       // EDIT THE 2 LINES BELOW AS REQUIRED
      $email_to = "example@gmail.com";
      $email_subject = "Sree Vizag Marketing-Tiles Enquiry";
													
													
      $first_name = $_POST['name']; // required
      $email_from = $_POST['email']; // required
      $phone = $_POST['phone']; // not required
      $comments = $_POST['comments']; // required
													
													
      $email_message .= "First Name: ".$first_name."\
\
";
      $email_message .= "Email: ".$email_from."\
\
";
      $email_message .= "Telephone: ".$phone."\
\
";
      $email_message .= "Comments: ".$comments."\
";

     //create email headers
      $headers = "From: $email_from";
      'Reply-To: '.$email_from."\\r\
" .
      'X-Mailer: PHP/' . phpversion();
												
												
     $mail_sent = @mail($email_to, $email_subject, $email_message, $headers);

                                                                                                 
     echo $mail_sent ? "Mail sent" : "Mail failed";
}
?>

Using this code the email does not show up in the gmail inbox.Any kind help will be appreciated.

srinivas.

What happens when you run it? Do you see ‘mail sent’ or ‘mail failed’? Consider removing the @ from the mail() function, it might be suppressing a useful error message.

In any case, you form is vulnerable to email injection, and should be modified.

Nice spotting there. I suppose that should be a dot instead of a semi-colon :slight_smile:

Looks like you have a syntax error also. There is a semi-colon at the end of this line…

$headers = “From: $email_from”;

Doesn’t look like it should be there.