当第二次在php中发送不同的邮件时,如何删除附件形式的phpmailer [英] How do i remove attachment form phpmailer when sending a different mail for second time in php
本文介绍了当第二次在php中发送不同的邮件时,如何删除附件形式的phpmailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个php文件中,我需要向2个不同的ID发送2个不同的电子邮件.当我使用如下所示的两个变量时,它不起作用.
In a php file i need to send 2 different emails to 2 different id's. It did not work when i used two variables like this shown below.
require 'PHPmailer/class.phpmailer.php';
/* First Email*/
$email = new PHPMailer();
$email->From = 'admin@mywebsite.com';
$email->FromName = 'My Webisite';
$email->Subject = 'Subject of first email';
$email->Body = 'Body of the message to first person';
$email->AddAddress( 'to first person' );
$file_to_attach = 'path of the file';
$email->AddAttachment( $file_to_attach, '' );
$email->Send();
/* Second Email*/
require 'PHPmailer/class.phpmailer.php';
$confirm = new PHPMailer();
$confirm-> From = 'noreply@mywebsite.com';
$confirm-> FromName = 'Admin @ MyWebsite';
$confirm-> Subject = 'Subject of second email';
$confirm-> Body = 'Body of second email';
$confirm-> AddAddress('Email ID of second person');
$confirm->Send();
但是如果我两次使用相同的变量,我将如下所示工作
But if i use the same variable twice i will work as shown below
require 'PHPmailer/class.phpmailer.php';
/* First Email*/
$email = new PHPMailer();
/* Same as above*/
$file_to_attach = 'path of the file';
$email->AddAttachment( $file_to_attach, '' );
$email->Send();
/* Second Email*/
$email-> From = 'noreply@mywebsite.com';
$email-> FromName = 'Admin @ MyWebsite';
$email-> Subject = 'Subject of second email';
$email-> Body = 'Body of second email';
$email-> AddAddress('Email ID of second person');
$email->Send();
但是问题是它正在将附件发送到两个电子邮件ID.请帮我如何不将附件发送到第二个ID.
推荐答案
unset($mail->attachment)
将不起作用,因为attachment
是受保护的变量.而是使用:
unset($mail->attachment)
won't work as attachment
is a protected variable. Instead use:
$email->clearAttachments();
这篇关于当第二次在php中发送不同的邮件时,如何删除附件形式的phpmailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文