我一直在尝试通过带有php的表单进行测试以发送电子邮件,但它对我不起作用。将返回以下消息:发送电子邮件时出错。也就是说,变量boolean $ sent的值为false。
我使用Apache,XAMPP for Windows 10和Netbeans 8.2开发环境
让我们先看看是否有人可以帮助我。
这是给出错误的代码:
<?php
$for = 'email@example.com';
$title = 'Sending email from PHP';
$message = '<html><head><title> Email with HTML </title></head>
<body><h1> Email with HTML </h1>
This is an email that is sent in HTML format
<hr>Sent by my program in PHP</body></html>';
$headers = 'MIME-Version: 1.0'. "\r\n";
$headers. = 'Content-type: text / html; charset = utf-8 '. "\r\n";
$headers. = 'From: Name1 Name 2 <info@example.com>';
$sent = mail ($for, $title, $message, $headers);
if ($sent)
echo 'Email sent correctly';
else
echo 'Error in sending the email';
?>
答案 0 :(得分:0)
据我所知,你有一些连接问题,我不确定那些实际存在于你的代码中或是由于复制粘贴。请尝试以下操作,在语句结束时处理$header
连接和分号;
。
<?php
$for = 'email@example.com';
$title = 'Sending email from PHP';
$message = '<html>'.
'<head> <title> Email with HTML </title> </head>'.
'<body> <h1> Email with HTML </h1>'.
'This is an email that is sent in HTML format.'
'<hr>'.
'Sent by my program in PHP'.
'</body>'.
'</html>';
$headers = 'MIME-Version: 1.0'. "\ r \ n";
$headers .= 'Content-type: text / html; charset = utf-8 '. "\ r \ n";
$headers .= 'From: Name1 Name 2 <info@example.com>';
$sent = mail ($for, $title, $message, $headers);
if ($sent)
echo 'Email sent correctly';
else
echo 'Error in sending the email';
?>