电子邮件地址中的Unicode字符-phpmailer-php
我有一个脚本,通过一个表格向报名参加比赛的人发送确认电子邮件 电子邮件是对象的属性,在该对象的构造函数中按以下方式设置: 注意,转换是我放在那里试图解决这个问题的东西,但它不起作用 然后通过同一对象上的公共函数发送: 查看下面的emailMessage类,它是PHPMailer的扩展电子邮件地址中的Unicode字符-phpmailer-php,php,unicode,phpmailer,Php,Unicode,Phpmailer,我有一个脚本,通过一个表格向报名参加比赛的人发送确认电子邮件 电子邮件是对象的属性,在该对象的构造函数中按以下方式设置: 注意,转换是我放在那里试图解决这个问题的东西,但它不起作用 然后通过同一对象上的公共函数发送: 查看下面的emailMessage类,它是PHPMailer的扩展 该地址没有通过phpmailer的validateAddress函数,其中regex甚至没有启用utf8支持。尽管即使启用utf8模式,它仍然无法验证 您应该启用异常,以便查看它们。您可以通过将true传递给构造函
该地址没有通过phpmailer的
validateAddress
函数,其中regex甚至没有启用utf8支持。尽管即使启用utf8模式,它仍然无法验证
您应该启用异常,以便查看它们。您可以通过将true
传递给构造函数来启用异常:
class emailMessage extends PHPMailer
{
public function __construct()
{
parent::__construct(true);
这样,您就会看到无效地址的异常。您可以尝试验证其中一个有问题的地址吗?如果该库拒绝邮件,则您提供的地址与管理RFC的当前一代电子邮件不兼容。如果它真的通过了,那么您可能需要向PHPMailer人员提交一个bug。你也应该看一看。更改你的密码伙计。@Charles有趣的是,
is_email
的php版本返回false,而java版本返回true,似乎php版本不处理utf8:XYes,这是我的真实数据,不,我没有思考。更改了密码。谢谢你指出这一点!:)好吧,这不是一封有效的电子邮件。有没有关于给愚蠢到购买非ASCII字母域名的可怜家伙发送电子邮件的建议。。。我认为,一个包含æå的URL恰当地使用了某种形式的字符替换,尽管我似乎找不到任何相关文档?谢谢提示!:)。我试过了,正如你所说的,我得到了一个无效电子邮件地址的例外。然而,这并不能解决我的问题。我仍然需要某种方式向这些地址发送电子邮件。有什么建议吗?@Fireworm你需要使用不同的库或修改phpmailerI,我想我可以通过用地址中的其他内容替换æåcharecters向他们发送邮件。例如,如果我去这个地址:http://æøåhghg.dk/我实际上去了。如果我能在某个地方找到翻译表,我也许能自己翻译地址。有人知道我在哪里能找到它吗?不,那也不行。当æå出现在@之前时,错误也会出现,因此翻译域不会有任何帮助。如果有人感兴趣,我确实找到了一个翻译域的工具:
public function sendMail($subject, $message)
{
global $CFG;
$mail = new emailMessage();
$mail->Subject = $subject;
$mail->setContent($message);
$sentMails = 0;
$errors = "";
$mail->AddAddress($this->email);
if(!$mail->Send())
{
$errorCount++;
$errors .= 'Mailer error: ' . $mail->ErrorInfo . "<br/>";
}
else
{
$sentMails++;
}
$mail->ClearAddresses();
if($sentMails > 0)
return true;
if($errors != "")
{
echo $errors;
return false;
}
}
class emailMessage extends PHPMailer
{
public function __construct()
{
$this->CharSet="UTF-8";
$this->AddEmbeddedImage(calculateRelativePath() . "img/camp_carnival.png", "camp_carnival");
$this->IsSMTP(); // telling the class to use SMTP
//$this->Host = $CFG->smtpServer; // SMTP server
//$this->SMTPDebug = 2; // enables SMTP debug information (for testing)
$this->SMTPAuth = true; // enable SMTP authentication
$this->SMTPSecure = "tls"; // sets the prefix to the servier
$this->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$this->Port = 587; // set the SMTP port for the GMAIL server
$this->Username = "x@domain.com"; // GMAIL username
$this->Password = ""; // GMAIL password
$this->SetFrom('x@domain.com', 'Lasse Rørbæk');
$this->AddReplyTo("x@domain.com","Lasse Rørbæk");
$this->WordWrap = 50;
$this->IsHTML(true);
}
public function setContent($content)
{
$this->Body = '
<table width="100%" style="background-color:rgb(239,233,217);">
<tr>
<td height="15">
</td>
</tr>
<tr>
<td width="100%" style="margin:20px 0px 30px 0px;">
<center>
<img width="80%" alt="Camp*Carnival" src="cid:camp_carnival"/>
</center>
</td>
</tr>
<tr>
<td style="width:100%;padding:20px 70px;">
<div style="margin:auto;width:65%;border:3px solid rgba(0,0,0,0.5);border-radius: 7px;padding:10px 7px;background-color:rgba(255,255,255,0.7);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#7FFFFFFF,endColorstr=#7FFFFFFF);">
' . $content . '
</div>
</td>
</tr>
</table>';
}
}
class emailMessage extends PHPMailer
{
public function __construct()
{
parent::__construct(true);