Jump to content

Php Mail Function Isn't Working


unemployment

Recommended Posts

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

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!"; }

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?

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);

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.