【问题标题】:Email file is sending email two times using php mail function电子邮件文件使用php邮件功能发送电子邮件两次
【发布时间】:2012-12-12 13:15:33
【问题描述】:

我的三个问题,尝试了不同的组合但没有结果,谷歌搜索但几乎没有帮助--

  1. 我收到了两次邮件,把myemail@emailserver.com换成email id看看结果。
  2. 在执行此文件时,我正在获取图像,但是我想要文本“已发送电子邮件”。
  3. 传递带有标签的完整 HTML 内容,而不是在电子邮件中呈现 HTML。

我的工作代码-->

<?php
    header('Content-type: image/jpeg');
    $jpg_image = imagecreatefromjpeg('http://dummyimage.com/600x400/f5f5f5/fff.jpg');
    $black = imagecolorallocate($jpg_image, 1, 1, 1);
    $font_path = 'myfont/arial.ttf';
    $text = "Swapnesh Sinha!";
    imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
    $tip = imagejpeg($jpg_image);
    $imageData = base64_encode($tip);
    //$src = 'data: '.mime_content_type($jpg_image).';base64,'.$imageData;
    imagedestroy($jpg_image);
?>

<html>
<head></head>
<body>
<p>

<?php

$to = 'myemail@emailserver.com';
$subject = "Thisa is a email test to find image work";
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MY SITE TITLE</title>
</head><body><table><tr><td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td></tr><tr><img src="'.'http://mysiteurl/addtext.php'.'" /></tr></table></body></html>';
$headers = 'From: myemail@emailserver.com' . "\r\n" .
           'Reply-To: myemail@emailserver.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

$bool = mail($to, $subject, $message, $headers);

if($bool)
echo "Email Sent"; 
else
echo "Email Not Sent";

?>

</body>
</html>

注意 - 在&lt;img src="'.'http://mysiteurl/addtext.php'.'" /&gt;

http://mysiteurl/addtext.php 与我们拥有上述所有内容的地方相同。

【问题讨论】:

  • 仅供参考,我尝试使用 base64_encode 但也无法从中实现:(

标签: gd html-email php php-gd


【解决方案1】:

我要做的第一件事是检查您的 apache/IIS 日志,以确保该 URL 没有被调用两次(只是一个健全性检查)。

如果您添加到 OP 的 PHP 页面是 http://mysiteurl/addtext.php,那么它将被调用两次,一次渲染 HTML,然后浏览器会在渲染 @987654323 时再次调用它@标签。

要解决此问题,您需要将其拆分为两个 PHP 文件(推荐),或者传递一个 GET 参数来切换图像处理。

您还需要添加$headers .= "Content-type: text/html\r\n";,以便将电子邮件呈现为 html 而不是纯文本。

【讨论】:

  • 从哪里到哪里或者我需要从这个文件中分离出哪些代码?
  • 创建第二个文件,该文件不返回 HTML,只返回图像,例如 img-with-text.phponly 进行图像处理并返回图像内容类型。 IE。您在 OP 中拥有的第一个 php 块。然后在 HTML 页面中将图像标签更改为 mysiteurl/img-with-text.php'.'" />
  • 现在非常接近 ..唯一的问题是我的 html 标签在电子邮件中以相同的方式出现(未处理 html 标签的呈现:(在收到的电子邮件中)
  • 您只需要设置电子邮件的标题。 $headers .= "Content-type: text/html\r\n";
  • ...完美..谢谢您的所有帮助..已经投票并接受它作为答案..只需在您的答案中添加标题内容,以便它清楚地反映您完成后的努力那么将接受作为答案..干杯! :)
猜你喜欢
  • 2014-05-23
  • 2012-02-04
  • 2014-04-30
  • 1970-01-01
  • 2020-03-26
  • 2021-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多