【发布时间】:2018-05-30 13:43:13
【问题描述】:
我一直在尝试使用 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';
?>
【问题讨论】:
-
这看起来确实是一个硬语法错误:
$ for等等不是有效的 PHP 代码 -
您在
...HTML format.'之后没有正确连接,缺少.。$headers之后缺少分号。话虽如此,给自己找一个像样的 IDE,它会提前掌握这些东西。并启用 php 错误报告(如果您还没有)。 -
你试过不带标题发送吗?
-
复制粘贴代码的时候已经加了空格,没有加连接点。我还是没解决。
-
如果我检查发送不带标题的电子邮件。
标签: php forms xampp phpmailer sendmail