kryppienation Posted June 18, 2009 Share Posted June 18, 2009 Hello everyone, i'm trying to just run a very simple email script to send a message, it's not working properly i keep getting the "mail failed" when i run the script. Can anyone tell me what's wrong? <?php //define the receiver of the email $to = '[email protected]'; //define the subject of the email $subject = 'Test email'; //define the message to be sent. Each line should be separated with \n $message = "Hello."; //define the headers we want passed $headers = "From: [email protected]\r\nReply-To: [email protected]"; //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> Link to comment https://forums.phpfreaks.com/topic/162831-problem-with-emailing/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2009 Share Posted June 18, 2009 Remove the @ in front of the function call because that would hide any error that would tell you why it failed and add the following two debugging lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/162831-problem-with-emailing/#findComment-859252 Share on other sites More sharing options...
kryppienation Posted June 18, 2009 Author Share Posted June 18, 2009 i got the following results when i did those things. 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 C:\htdocs\kryppienation\testemail.php on line 23 Mail failed <?php ini_set("display_errors", "1"); error_reporting(E_ALL); //define the receiver of the email $to = '[email protected]'; //define the subject of the email $subject = 'Test email'; //define the message to be sent. Each line should be separated with \n $message = "Hello World!\n\nThis is my first mail."; //define the headers we want passed. Note that they are separated with \r\n $headers = "From: [email protected]\r\nReply-To: [email protected]"; //send the email $mail_sent = mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> Link to comment https://forums.phpfreaks.com/topic/162831-problem-with-emailing/#findComment-859256 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2009 Share Posted June 18, 2009 So, do you have a mail server installed on your localhost computer, listening to port 25? Link to comment https://forums.phpfreaks.com/topic/162831-problem-with-emailing/#findComment-859266 Share on other sites More sharing options...
kryppienation Posted June 18, 2009 Author Share Posted June 18, 2009 I sure do, i'm wondering if i didn't set something up right in the php.ini file? I'm not really sure what to look for in there, do you have any advice on what needs changed or anything? This is the first time that i've tried to incorperate email into the code. Link to comment https://forums.phpfreaks.com/topic/162831-problem-with-emailing/#findComment-859269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.