unemployment Posted October 12, 2012 Share Posted October 12, 2012 I'm in the process of trying to set up php generated emails. I have recently built my new server but I can't seem to get PHP to send emails. I tested the code out below but it responds with message delivery failed. <?php $to = "[email protected]"; $header = "From: {$to}"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body, $header)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> The odd thing is that I also tried: if ( function_exists( 'mail' ) ) { echo 'mail() is available'; } else { echo 'mail() has been disabled'; } and it returned that the mail() is available. What can I do to get this working? Is this a server configuration issue? Link to comment https://forums.phpfreaks.com/topic/269401-php-mail-function-isnt-working/ Share on other sites More sharing options...
darkfreaks Posted October 12, 2012 Share Posted October 12, 2012 i am guessing you have a MIME header problem..... $header = ‘From: ‘.$to.PHP_EOL; $header .='Reply-To: ‘.$to.'.PHP_EOL; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $success = mail($to,$subject,$body,$header); if($success) { echo "Mail Sent!"; } else { echo "Mail Not Sent!"; } Link to comment https://forums.phpfreaks.com/topic/269401-php-mail-function-isnt-working/#findComment-1384878 Share on other sites More sharing options...
unemployment Posted October 13, 2012 Author Share Posted October 13, 2012 i am guessing you have a MIME header problem..... $to = '[email protected]'; $header = 'From: '.$to.PHP_EOL; $header .='Reply-To: ‘.$to.'.PHP_EOL; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $success = mail($to,$subject,$body,$header); if($success) { echo "Mail Sent!"; } else { echo "Mail Not Sent!"; } Running this code returned mailed not sent! What do I do? What is the issue? Link to comment https://forums.phpfreaks.com/topic/269401-php-mail-function-isnt-working/#findComment-1384926 Share on other sites More sharing options...
Jessica Posted October 13, 2012 Share Posted October 13, 2012 You may have a problem with your mail server's configuration. Link to comment https://forums.phpfreaks.com/topic/269401-php-mail-function-isnt-working/#findComment-1384927 Share on other sites More sharing options...
Pikachu2000 Posted October 13, 2012 Share Posted October 13, 2012 Something looks off about this line, no? $header .='Reply-To: ‘.$to.'.PHP_EOL; Link to comment https://forums.phpfreaks.com/topic/269401-php-mail-function-isnt-working/#findComment-1384928 Share on other sites More sharing options...
PFMaBiSmAd Posted October 13, 2012 Share Posted October 13, 2012 When developing and debugging php code, you need to have php's error_reporting set to E_ALL and display_errors set to ON to get php to help you by reporting and displaying all the errors it detects. For runtime errors in your main file, you can set the two setting in your code by adding the following - ini_set("display_errors", "1"); error_reporting(-1); Link to comment https://forums.phpfreaks.com/topic/269401-php-mail-function-isnt-working/#findComment-1384930 Share on other sites More sharing options...
unemployment Posted October 13, 2012 Author Share Posted October 13, 2012 You may have a problem with your mail server's configuration. Apparently I needed postfix installed. Didn't know that! Link to comment https://forums.phpfreaks.com/topic/269401-php-mail-function-isnt-working/#findComment-1384933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.