Jump to content

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@example.com";
$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 = 'myemail@gmail.com';
$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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.