电子邮件文件使用php邮件功能发送了两次电子邮件 [英] Email file is sending email two times using php mail function

查看:74
本文介绍了电子邮件文件使用php邮件功能发送了两次电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My three concerns, tried different combos with no result, googled but little or no help --

  1. 我收到了两次电子邮件,将myemail@emailserver.com更改为电子邮件ID以查看结果.
  2. 执行此文件时,我正在获取图像,但是我想输入文本已发送电子邮件".
  3. 传递带有标签的完整HTML内容,而不是通过电子邮件呈现HTML.
  1. I received two times the email,change myemail@emailserver.com to the email id to see the result.
  2. While executing this file I am getting image, however I want to have text "Email Sent".
  3. Full HTML content with tag is passed instead of HTML rendering in email.

我的工作代码->

<?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>

注意-在<img src="'.'http://mysiteurl/addtext.php'.'" />

http://mysiteurl/addtext.php与上述所有内容相同.

http://mysiteurl/addtext.php is the same where we have all this above content.

推荐答案

我要做的第一件事是检查您的apache/IIS日志,以确保不会两次调用该URL(只是进行完整性检查).

First thing I'd do is check your apache/IIS logs to ensure that the URL isn't being called twice (just a sanity check).

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

If the PHP page you've added to your OP is http://mysiteurl/addtext.php, then it would be called twice, once renderering the HTML, then the browser would call it again when rendering the <img ...> tag.

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

To fix this you need to either split it into two PHP files (recommended), or pass a GET parameter to toggle the image processing.

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

You'll also need to add $headers .= "Content-type: text/html\r\n"; so that the email is rendered as html and not plain text.

这篇关于电子邮件文件使用php邮件功能发送了两次电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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