PHP 没有将 HTML 模板发送到电子邮件
PHP not sendig HTML template to email
我的问题是,当您注册用户时会生成随机代码,该代码会发送到电子邮件中,我为包含基本文本和样式的电子邮件制作了一个模板,此电子邮件仅更改了基本 link生成的代码。所以一切都应该按照我的意思工作,但目前在注册过程中会收到电子邮件,但没有我提供的样式。下面的代码。
$to = $email;
$subject = "Registration Confirmation";
$link = "<a href='".DIR."/activation?x=$latest_id&y=$activasion'>".DIR."/activation?x=$latest_id&y=$activasion</a>";
$headers = "MIME-Version: 1.0" . "\r";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = file_get_contents("inc/user_register.html");
$message = str_replace('[link]', $link, $message);
mail($to, $subject, $message, $headers);
header("location: /login?action=joined");
您在第 headers[] 处缺少 \n。您也可以尝试通过这种方式设置 header.
// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Additional headers
$headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
$headers[] = 'From: Birthday Reminder <birthday@example.com>';
$headers[] = 'Cc: birthdayarchive@example.com';
$headers[] = 'Bcc: birthdaycheck@example.com';
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
问题已解决
我使用的是从 google 字体网站导入的字体。我已将其从样式中删除并按我想要的方式工作。
我的问题是,当您注册用户时会生成随机代码,该代码会发送到电子邮件中,我为包含基本文本和样式的电子邮件制作了一个模板,此电子邮件仅更改了基本 link生成的代码。所以一切都应该按照我的意思工作,但目前在注册过程中会收到电子邮件,但没有我提供的样式。下面的代码。
$to = $email;
$subject = "Registration Confirmation";
$link = "<a href='".DIR."/activation?x=$latest_id&y=$activasion'>".DIR."/activation?x=$latest_id&y=$activasion</a>";
$headers = "MIME-Version: 1.0" . "\r";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = file_get_contents("inc/user_register.html");
$message = str_replace('[link]', $link, $message);
mail($to, $subject, $message, $headers);
header("location: /login?action=joined");
您在第 headers[] 处缺少 \n。您也可以尝试通过这种方式设置 header.
// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Additional headers
$headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
$headers[] = 'From: Birthday Reminder <birthday@example.com>';
$headers[] = 'Cc: birthdayarchive@example.com';
$headers[] = 'Bcc: birthdaycheck@example.com';
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
问题已解决
我使用的是从 google 字体网站导入的字体。我已将其从样式中删除并按我想要的方式工作。