SkyTec SkyTec - 7 months ago 19
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?

UPDATE:

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// 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: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

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


Always I got failed message

NEW:

enter image description here
enter image description here

Answer

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

<?php
//debug start - comment on production
error_reporting(E_ALL);
ini_set('display_errors', '1');
//debug end
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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