我刚刚更改了一些代码,以便能够使用我的邮件再次发送邮件。
起初,由于此行不推荐使用函数eregi_replace
,我出现了500错误:
$body = eregi_replace("[\]",'',$body);
我将其更改为:
$body = preg_replace("[\]",'',$body);
但是现在我无法发送电子邮件了,在控制台中我没有错误(我使用ajax发布到脚本),但是在网络标签中,当我查看响应时,这就是我得到的:
Message body empty
Message body empty
{"type":"error","text":"Could not send mail! Please check your PHP mail configuration."}
我发送了两封邮件,所以双封邮件是正确的。
这是我要发送的正文:
$body = "
<div id='sig' style='min-height: 50px; line-height: 17px; margin: 6px 0; padding-top: 0px; padding-bottom: 8px; font-family: calibri, Arial, Sans-Serif; font-size: 13px; color: #5C5C5C; min-width: 530px;'>
<div style=' padding-left: 10px;'>
<br>
<br>
Geachte heer/mevrouw " . $name . ",<br>
<br>
Bedankt voor uw aanvraag bij ".$naambedrijf.".<br>
Wij nemen binnen zo spoedig mogelijk contact met u op.
<br><br>
Met vriendelijke groet, <br>
<br>
".$naambedrijf."<br>
<br>
<br>
</div>
<table height='120' border='0' width='100%' cellspacing='0' cellpadding='0' style='border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted; color: #5C5C5C; font-size:10pt;line-height:22px;'>
<tr>
<td width='140' valign='top' style='padding-left:10px;padding-top:20px;'>
".$adres."
</td>
<td width='180' valign='top' style='padding-left:10px;padding-top:20px;'>
".$gegevenscontact."
</td>
<td align='right' style='padding-right:10px;padding-top:5px;'>
<a href='#' title='Ga naar ".$sitenaam."'><img src='".$logo."' alt='Ga naar ".$sitenaam."' style='text-align: right; margin:0px; padding: 0px;max-height:65px;' border='0'></a>
</td>
</tr>
</table>
<div style='color:#a3a3a3; font-size:11px;margin-top:6px;line-height:14px;'>
Dit e-mailbericht is uitsluitend bestemd voor de geadresseerde. Als dit bericht niet voor u bestemd is, wordt u vriendelijk verzocht dit aan de afzender te melden. ".$naambedrijf." staat door de elektronische verzending van dit bericht niet in voor de juiste en volledige overbrenging van de inhoud, noch voor tijdige ontvangst daarvan. Voor informatie over ".$naambedrijf." raadpleegt u <a href='hhtp://".$sitenaam."' style='color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;' target='_BLANK'>".$sitenaam."</a>.
</div>
</div>
</div>";
$body = preg_replace("[\]",'',$body);
// $mail->AddReplyTo("info@".$sitenaam."","".$naambedrijf."");
$mail->SetFrom('info@'.$sitenaam.'', ''.$naambedrijf.'');
$address = $email;
$mail->AddAddress($address, $voornaam);
$mail->Subject = "Bedankt voor uw offerteaanvraag bij ".$naambedrijf.".";
$mail->AltBody = "Om dit bericht te bekijken, heeft u een email programma nodig dat HTML-mail kan bekijken!"; // optional, comment out and test
$mail->MsgHTML($body);
该如何解决?
答案 0 :(得分:1)
您需要转义“ \”。
尝试
$body =preg_replace("/[\\\\]/i",'',$body);
为什么我们使用四个反斜杠而不是一个?看看https://ubuntuforums.org/archive/index.php/t-1245302.html
i选项用于不区分大小写的匹配,例如eregi_replace,在这里可能是多余的。