0

I have created a form and written a php script to send a mail after clicking the submit button, and display a thank you message after sending the mail. The "Thank you" message is put into another HTML page.

I put those to WWW folder in WAMP server and try it. The "Thank you" page is displayed but the mail is not sent to my mail account.

Why did it not send my mail? Is it necessary to host the web site to do this?

This is the code that I'm using:

<?php
$email_from = 'aa@gmail.com';
$email_subject = "Arrange new Safari service";
$email_body = "You have received a new message from  $name.\n"
$to = "aa@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thanking.html');
?>
Damien Pirsy
  • 25,319
  • 8
  • 70
  • 77
hazi
  • 53
  • 1
  • 5

4 Answers4

1

Please read here Sending email from localhost

And here http://forums.devshed.com/mail-server-help-111/how-to-set-up-php-ini-to-send-mail-from-106329.html

Community
  • 1
  • 1
Simone
  • 20,302
  • 14
  • 79
  • 103
1

If you use the php mail() function, you need an smtp server. Right, that might run on you hosting.

You might also use a librairy like http://swiftmailer.org/ to get it easier (you will be able to use remote smtp servers without pain)

7seb
  • 172
  • 10
0

There appear to be some syntax errors in the code you have supplied:

$email_from = 'aa@gmail.com';
$email_subject = "Arrange new Safari service";
$email_body = "You have received a new message from  $name.\n";
$to = "aa@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thanking.html');

I have attempted to fix the syntax above.

Treffynnon
  • 21,365
  • 6
  • 65
  • 98
0

You need to configure PHP to use a working SMTP service in order to send SMTP email.

Basically, it appears that the SMTP configuration for your PHP instance is using default values, which point to localhost. But your local computer doesn't seem to be running an SMTP service. So you'll need to point is to a server that is running one, and one which your application is permitted to use.

You have to configure your php.ini with a valid smtp server and email address.

Check this article http://www.sitepoint.com/advanced-email-php/

niko
  • 9,285
  • 27
  • 84
  • 131