【发布时间】:2014-09-26 04:14:05
【问题描述】:
如何修改此代码以添加 MIME 并包含电子邮件的文本版本?就像代码成功发送了 HTML 格式的电子邮件一样。我正在使用文本编辑器、PHP、HTML 和 mySQL 数据库。 (此代码的目的是向新注册的用户发送一个链接,用于验证注册过程中提供的电子邮件地址。)
$first_name =$register_data['first_name'];
$to =$register_data['email'];
$from ='support@mysite.com';
$subject = 'Verify email address to activate account';
$email_code =$register_data['email_code'];
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$path ="activate.php?email=" . $to . "&email_code=" . $email_code . "";
$message = <<<EOF
<html>
<head>
<base href="https://mysite.com">
</head>
<header>
<img src="images/logo.png"><br>
<img src="images/header.png">
</header>
<body>
<br>
<table style="width:600px">
<tr>
<td style="width:10px"></td>
<td>Dear $first_name,</td>
<td style="width:10px"></td>
</tr>
<tr></tr>
<tr>
<td></td>
<td>Thank you for registering! To activate your account, please verify your email address address by clicking on the verify button below.</td>
<td></td>
</tr>
</table>
<p>
<table style="width:600px">
<tr>
<td style="width:10px"></td>
<td><center><a href =$path><img src="images/verify_button.png"></a></center></td>
<td style="width:10px"></td>
</tr>
</table>
</p>
<p>
<table style="width:600px">
<tr>
<td style="width:10px"></td>
<td>Thanks for registering!</td>
<td style="width:10px"></td>
</tr>
<tr>
<td style="width:10px"></td>
<td>-- mysite</td>
<td style="width:10px"></td>
</tr>
</table>
</p>
</body>
</html>
EOF;
mail ($to, $subject, $message, $headers);
【问题讨论】:
-
考虑使用PHP Mailer:github.com/PHPMailer/PHPMailer