PHPMailer “$mail->MsgHTML($msg)” issue with “$msg”

此生再无相见时 提交于 2019-12-25 08:31:40

问题


I'm asking here because I did not got an answer from OVH (my hosting). Here is the problem : If I replace $mail->MsgHTML($msg) with $mail->MsgHTML($_POST['message']), I receive the mail instantly with headers, name, email, subject and the message. But when I put $msg instead, I receive no mail.

$msg='Name:'.$_POST['name'].'<br />
Email:'.$_POST['email'].'<br />
Subject: '.$_POST['subject'].'<br />
IP:'.$_SERVER['REMOTE_ADDR'].'<br /><br />

Message:<br /><br />

'.nl2br($_POST['message']).'

';

entire PHP (from FancyAJAXForm):

<?php
/* config start */

$emailAddress = 'my mail address';

/* config end */

require "class.phpmailer.php";

foreach($_POST as $k=>$v)
{
if(ini_get('magic_quotes_gpc'))
$_POST[$k]=stripslashes($_POST[$k]);

$_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}


$msg='Name:'.$_POST['name'].'<br />
Email:'.$_POST['email'].'<br />
Subject: '.$_POST['subject'].'<br />
IP:'.$_SERVER['REMOTE_ADDR'].'<br /><br />

Message:<br /><br />

'.nl2br($_POST['message']).'

';

$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "Contact Form: ".mb_strtolower($_POST['subject'])." from    ".$_POST['name']."";

$mail->MsgHTML($msg);

$mail->Send();

?>

回答1:


Ok I got the problem solved.

I've replace $mail->msgHTML($msg) with the body function :

$mail->IsHTML(true);
$mail->Body='Name:  '.$_POST['name'].'<br />
Email:  '.$_POST['email'].'<br />
Sujet:  '.$_POST['subject'].'
<br /><br />

'.nl2br($_POST['message']).'

<br /><br /> 
Browser:  '.$_SERVER['HTTP_USER_AGENT'].'<br />
IP:  '.$_SERVER['REMOTE_ADDR'].'<br />
';

$mail->Send();

It works perfectly! Thanks to all participants!




回答2:


I know this isn't exactly timely, but I found an alternative solution:

I had a similar problem, but I had some pages that worked and some that didn't. I tried your solution, but it gave me the same results.

Then I looked at the html source of the emails from the working pages, and noticed that I had included the opening and closing html and body tags, and I hadn't included them in the non-working pages. That's all it took, and $mail->msgHTML($msg) worked for me.

Hope this helps.



来源:https://stackoverflow.com/questions/10373603/phpmailer-mail-msghtmlmsg-issue-with-msg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!