PHP邮件程序无法发送html消息
我尝试通过PHP发送HTML邮件,但没有任何效果。我尝试了两种选择 一个具有PHP邮件程序无法发送html消息,php,html,Php,Html,我尝试通过PHP发送HTML邮件,但没有任何效果。我尝试了两种选择 一个具有文件\u获取\u内容: <?php $to = 'teas@gmail.com'; $subject = 'Marriage Proposal'; $from = 'support@blabla.com'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $hea
文件\u获取\u内容
:
<?php
$to = 'teas@gmail.com';
$subject = 'Marriage Proposal';
$from = 'support@blabla.com';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = file_get_contents("email_template.html");
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
还有一个PHP字符串中包含HTML:
<?php
$to = 'anthony@gmail.com';
$subject = 'Marriage Proposal';
$from = 'peterparker@email.com';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Jane!</h1>';
$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
这两种功能的响应是:
无法发送电子邮件。请再试一次。无法发送电子邮件。请
再试一次
谁能告诉我出了什么问题吗?只要在php邮件中启用HTML即可
$mail->isHTML(true);
请参阅您是否在
php.ini
中正确设置了SMTP服务器?一切正常。到目前为止,我总共以纯文本发送了10000封电子邮件。但当我实现HTML时,它会出错。如果这些普通的电子邮件都被发送了,那就意味着一切都很好。idk要澄清标题,这是在php中使用mail()函数,而不是“PHPMailer”。很大的不同。这里提供了额外的标题行:这些可能有用,也可能没有帮助,只是值得一读/尝试。如果您无法解决您的问题,我强烈建议,强烈建议使用PHPMailer。他没有使用PHPMailer库。我现在需要联系支持人员,以便他们可以添加它。这是共享的hosting@TFennis我让他试试这种方法,好吗?你称之为支持?cpanel中没有php.ini文件。所以我应该创建新的吗?还是联系主机?这是我正在使用的共享主机