Jump to content

[SOLVED] why mail() doesnt work


tawevolution

Recommended Posts

Hi,

 

Im trying to use the mail() function. Here is my code:

 

<?php
$to = "[email protected]";
$subject = "subject here!";
$body = "this is the body section of the email message";


if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

 

Every time i run the script, it says "Message successfully sent!".... so i then go over to my email inbox (i set the $to to my own email as a test) and the email never comes through. I have checked my email spam box, and i have tried several different email accounts (using diff email providers) .... none of which get through.

 

Someone told me to make sure the 'safe_mode' was off, and 'register_globals' was on - of which they both are ...... any ideas?????

 

Thanks

Evo

Link to comment
https://forums.phpfreaks.com/topic/50159-solved-why-mail-doesnt-work/
Share on other sites

Hello

I have just tried to run your code on my system which sows all errors for testing purposes and got the following error

Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Program Files\xampp\htdocs\phptest\mail.php on line 7

Message delivery failed...

 

try this but modify for taste

<?php
$to = "[email protected]";
$subject = "subject here!";
$body = "this is the body section of the email message";
$headers = 'From: Birthday Reminder <[email protected]>' . "\r\n";

if (mail($to, $subject, $body, $headers)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

Are you testing this on your own machine or on a live server? If its your own machine then check that you have set the SMTP setting in your php.ini file (set it to what ever your service providers smtp is)

 

Its on a live server .... so what should i do to make it work?

sorry for double post .....

 

I have marked this post as solved because I found out why it wasnt working. I was sending an email to my hostings email accounts - and it doesnt like that - so i just created temp @gmail.com accounts and set up forwarders :P

 

evo out

 

thanks for your hepl guys

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.