SkyTec SkyTec - 2 years ago 130
PHP Question

Php mail function failed

I have problem with php mail() function, I look up for configurations on w3schools for mail:

mail.add_x_header - "0"
SMTP - "localhost"
mail.log - "NULL"
smtp_port - "25"
sendmail_from - "NULL"
sendmail_path - "/usr/sbin/sendmail -t -i"

And by this I checked mine.

<?php echo phpinfo(); ?>

It is same!

Can anyone tell me what is problem, code is not problem. When I asked hosting support they just told me to use autoresponders. But how can I connect php code for registration with autoresponders... And this may be stupid but is there javascript way to send mail like on php with mail() function?


$to = ",";
$subject = "HTML email";

$message = "
<title>HTML email</title>
<p>This email contains HTML Tags!</p>

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <>' . "\r\n";
$headers .= 'Cc:' . "\r\n";

if(mail($to,$subject,$message,$headers)){ echo "sent"; }else echo "failed";

Always I got failed message


enter image description here
enter image description here

Answer Source

Working example for the mail() function straight from the PHP MANUAL (yes, it exists!)

//debug start - comment on production
ini_set('display_errors', '1');
//debug end
$to      = '';
$subject = 'the subject';
$message = 'hello';
$headers = 'From:' . "\r\n" .
    'Reply-To:' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

   echo "sent"; 
   echo "failed";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download