我有一个用户群。每当新用户注册时,我都会通过php mail()向他们发送欢迎电子邮件。它工作得非常好。这是代码的邮件部分 -
new Duration(startDateTime, endDateTime).toStandardHours().getHours()
但是几乎相同的mail()代码,我用它来发送密码重置链接。不管用。虽然代码没有抛出错误,但邮件没有交付。我已经检查过注册邮件是否完美且快速。不在这里。这是代码
$emailto = $useremail;
$toname = $username;
$emailfrom = 'hello@*****.com';
$fromname = '*****';
$subject = 'Welcome to ****';
$messagebody = 'Dear '.$name.'<br/><br/>Thank you for becoming a member in the family of <b>*******</b>.<br>Please enter your chosen <b>Username : '.$username.'</b> and the <b>Activation Code : '.$y.'</b> to complete your registration process.<br/><b/r> You can enter the details in the link: www.*****.com/reg_success.html<br/><b/r><b><i>The*****Team</b></i>';
$headers =
'Return-Path: ' . $emailfrom . "\r\n" .
'From: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" .
'X-Priority: 3' . "\r\n" .
'X-Mailer: PHP ' . phpversion() . "\r\n" .
'Reply-To: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-Transfer-Encoding: 8bit' . "\r\n" .
'Content-Type: text/html; charset=iso-8859-1' . "\r\n";
$params = '-f ' . $emailfrom;
$test = mail($emailto, $subject, $messagebody, $headers, $params);
答案 0 :(得分:6)
这是因为,在第二个代码中。
$emailto = '$useremail';
$toname = '$username';
在第一个代码中的位置
$emailto = $useremail;
$toname = $username;