PHP Mailer Script

I am trying to write a PHP mailer script for my website, in the file “contact.php”. I make my form’s action “contact.php”, but when I hit submit it redirects me to a blank page. The email itself also does not send. My PHP is as follows:
[php]

<?php $firstname = $_POST['first']; $lastname = $_POST['last']; $email = $_POST['address']; $comment = $_POST['question'] $email_from = '[email protected]' $email_subject = "A user has a question!" $email_body = "You have received a new message from $firstname $lastname. \n". "Here is the message:\n $comment". $to = "[email protected]"; $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to,$email_subject,$email_body,$headers); ?>

[/php]

And my form is:

Name
E-mail Questions/Concerns ...etc I would really love any help as I am still new to PHP. Thanks! :D

[php]$comment = $_POST[‘question’]
$email_from = ‘[email protected]
$email_subject = “A user has a question!”
$email_body = “You have received a new message from $firstname $lastname. \n”. “Here is the message:\n $comment”.[/php]
Your missing ; off the end of your lines.
Also you have no redirection so you will be sent to a blank page.

You should have error_reporting turned on, then you would have seen the syntax errors immediately. Do this at the top of your pages while developing and you’ll see your errors quickly.
[php]
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
[/php]
Also make sure to set the FROM address to an actual email address on the domain the form is sending from or you’ll have delivery issues cause it will likely be marked as spam on the receiving end.

I was a little confused when I first looked at your post cause there is actually a mailing library called PHPMailer, so I thought it was a question about that. Either way, you honestly should be using a library like that to send email, making your own mail code is a waste of time and usually will result in emails not being delivered cause you are missing crucial parts that an email needs. I have a detailed article about sending emails in php here http://amecms.com/article/Sending-email-in-PHP-and-reaching-the-inbox

Sponsor our Newsletter | Privacy Policy | Terms of Service