发送HTML邮件不工作 [英] Sending HTML mail not working

查看:412
本文介绍了发送HTML邮件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP mail()发送一个非常简单的HTML消息。目的是发送包含用户电子邮件地址和验证码的链接。当用户点击链接时,网站将收到电子邮件地址和代码,以验证用户的电子邮件地址是否准确。



起初,它工作,当它是只有HTML / BODY标签,标题和验证邮件链接。我在调试验证过程中多次发送电子邮件。然后我做了我认为是微小的变化,它退出工作。小改变被注释掉,如图所示。我添加了一个图像和几行文本。



不再发送电子邮件,我没有收到任何警告或错误。我已经删除了图像,额外的文字,并注释了添加的链接,但它仍然不起作用。谁能看到我在做错什么? (我改变了名字以保护无辜者)。

  function sendEmail($ email,$ code){

$ email = str_replace(@,%40,$ email);
$ to = $ email;
$ subject ='电子邮件验证';

$ headers =From:。 strip_tags(someone@somewhere.com)。 \r\\\
;
$ headers。=CC:\r\\\
;
$ headers。=MIME-Version:1.0\r\\\
;
$ headers。=Content-Type:text / html; charset = ISO-8859-1\r\\\
;

$ message =< html>< body> \r\\\
;
$ message。=< h2>谢谢!< / h2> \r\\\
;
// $ message。='< img src =http://www.mytestwebsite.com/images/logo.png>< br>';
// $ message。='感谢您在我们注册一个帐户。 ;
// $ message。='请通过点击下面的按钮来验证您的电子邮件地址。< br>';
// $ message。='< a href =http://www.mytestwebsite.com/verifyemail.php?email='.$email.'&code='.$code。'  验证电子邮件< / a>';
$ message。=< / body>< / html> \r\\\
;

$ message = wordwrap($ message,70,\r\\\
);
mail($ to,$ subject,$ message,$ headers);

}

我如何找出我的设置有什么问题?有没有网站会在我的代码中显示错误?



感谢您的帮助!
SH

解决方案

唯一可以阻止您发送电子邮件的内容是:

  $ email = str_replace(@,%40,$ email); 

因为您要将其发送到示例%40hostname.com



还要检查电子邮件是否发送使用:

  if(@mail($ to,$ subject,$消息,$ headers))
{
echoMail Sent successfullyfully;
} else {
echoMail Not Sent;
}


I am sending a very simple HTML message using PHP mail(). The purpose was to send a link that contained the user's email address and a verification code. When the user clicked the link, the site would receive the email address and code to verify that the user's email address was accurate.

At first, it worked, when it was nothing more than the HTML/BODY tags, a header, and the Verify Email link. I sent the email several times while debugging the verification process. Then I made what I considered to be minor changes, and it quit working. The minor changes are commented out as shown. I added an image and a couple lines of text.

It's not sending emails anymore, and I get no warnings or errors. I have removed the image, the extra text and commented out the addition of the link, but it will still not work. Can anyone see what I'm doing wrong? (I've changed names to protect the innocent.)

function sendEmail($email, $code) {

  $email = str_replace("@","%40",$email);
  $to = $email;
  $subject = 'Email Verification';

  $headers  = "From: " . strip_tags('someone@somewhere.com') . "\r\n";
  $headers .= "CC: \r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

  $message =  "<html><body>\r\n";
  $message .= "<h2>Thank you!</h2>\r\n";
  //$message .= '<img src="http://www.mytestwebsite.com/images/logo.png"><br>';
  //$message .= 'Thank you for registering an account with us. ';
  //$message .= 'Please verify your email address by clicking the button below.<br>';
  //$message .= '<a href="http://www.mytestwebsite.com/verifyemail.php?email='.$email.'&code='.$code.'">Verify Email</a>';
  $message .= "</body></html>\r\n";

  $message = wordwrap($message, 70, "\r\n");
  mail($to, $subject, $message, $headers);

}

How can I find out what's wrong with my setup? Is there a website that would display the errors in my code?

Thanks for your help! SH

解决方案

The only thing that seems to stop you from sending an email is:

$email = str_replace("@","%40",$email);

Because you are sending it to example%40hostname.com

Also to check if email is sent use:

if(@mail($to, $subject, $message, $headers))
{
  echo "Mail Sent Successfully";
}else{
  echo "Mail Not Sent";
}

这篇关于发送HTML邮件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆