php发送一封带有附件的邮件并复制不带附件
我今天做了我的第一个邮件程序 php 应用程序,非常好,发送了 2 个 pdf 附件,
但是为了保存记录,我需要一份邮件副本才能转到另一个邮件,但没有附件,
请问如何完成此操作?
这里的代码(编辑,抱歉,)
表单 html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Contact Form</title>
<meta name="Generator" content="Alleycode HTML Editor">
<meta name="Description" content="Your description here...">
<meta name="Keywords" content="Your keywords here...">
</head>
<body>
<form method="post" action="sendmail2.php">
<p>
<label>Name:</label> <br/> <input type="text" name="name" size="48" height="40"/>
</p>
<p>
<label>Email:</label> <br/> <input type="text" name="email" size="48" height="40"/>
</p>
<p>
<label>Child's Name:</label> <br/> <input type="text" name="childname" size="48" height="40"/>
</p>
<p>
<label>Site:</label>
<br/>
<textarea name="site" rows="2" cols="45" overflow:hidden>xx.com.au</textarea>
</p>
<p> </p>
<p>
<label>Days:</label>
<br/>
<textarea name="days" rows="2" cols="45" overflow:hidden>Monday, Tuesday, Wednesday, Thursday, Friday</textarea>
</p>
<p> </p>
<p>
<input type="submit" value="Send"/>
<a href="xx/form.html">clear</a></p>
</form>
</body>
</html>
sendmail2.php:
<?php
require("../phpmailer/class.phpmailer.php");
include("email.php");
$name = $_POST['name'];
$childname = $_POST['childname'];
$site = $_POST['site'];
$days = $_POST['days'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "xxx.com"; // SMTP servers
$mail->Username = "xxx"; // SMTP username
$mail->Password = "xxx"; // SMTP password
$mail->AddAddress($_POST['email']);
$mail->From = "[email protected]";
$mail->FromName = "xxx_online";
$mail->Subject = "Message from Alouette";
$mail->IsHTML(true);
$mail->Body = $message;
$mail->AddAttachment("../attachs/x.pdf");
$mail->AddAttachment("../attachs/xd.pdf");
if($mail->Send()) {
echo "Message sent! Thanks ! ";
print('<a href="xu/mail/form.html">Reset and Back</a>');
}
?>
email.php
<?php
$message = '
Hello '.$name.', <br/>
we have received your interest in child care services for '.$childname.' from the '.$site.' website. <br/>
<br/>
'.$days.'
<br/> <br/>
Should you have any questions regarding the information on our enrolment form or services please do not hesitate to contactkkk
<br/> <br/> <br/>
Regards, <br/>
<a href="mailto:[email protected]">[email protected]</a> <a href="http://www.nx.com.au" target="_new">www.neo-it.com.au</a>
<br/>
<strong>Childcare Management Services</strong>
<br/> <br/>
'
?>
非常感谢!
I did my first application of mailer php today, very nice, sending 2 pdf attachments,
but for record keeping, I need a copy of the mail to go to another mail, but with out the attachments,
how to accomplish this please??
here the code (edit, sorry, )
form html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Contact Form</title>
<meta name="Generator" content="Alleycode HTML Editor">
<meta name="Description" content="Your description here...">
<meta name="Keywords" content="Your keywords here...">
</head>
<body>
<form method="post" action="sendmail2.php">
<p>
<label>Name:</label> <br/> <input type="text" name="name" size="48" height="40"/>
</p>
<p>
<label>Email:</label> <br/> <input type="text" name="email" size="48" height="40"/>
</p>
<p>
<label>Child's Name:</label> <br/> <input type="text" name="childname" size="48" height="40"/>
</p>
<p>
<label>Site:</label>
<br/>
<textarea name="site" rows="2" cols="45" overflow:hidden>xx.com.au</textarea>
</p>
<p> </p>
<p>
<label>Days:</label>
<br/>
<textarea name="days" rows="2" cols="45" overflow:hidden>Monday, Tuesday, Wednesday, Thursday, Friday</textarea>
</p>
<p> </p>
<p>
<input type="submit" value="Send"/>
<a href="xx/form.html">clear</a></p>
</form>
</body>
</html>
sendmail2.php:
<?php
require("../phpmailer/class.phpmailer.php");
include("email.php");
$name = $_POST['name'];
$childname = $_POST['childname'];
$site = $_POST['site'];
$days = $_POST['days'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "xxx.com"; // SMTP servers
$mail->Username = "xxx"; // SMTP username
$mail->Password = "xxx"; // SMTP password
$mail->AddAddress($_POST['email']);
$mail->From = "[email protected]";
$mail->FromName = "xxx_online";
$mail->Subject = "Message from Alouette";
$mail->IsHTML(true);
$mail->Body = $message;
$mail->AddAttachment("../attachs/x.pdf");
$mail->AddAttachment("../attachs/xd.pdf");
if($mail->Send()) {
echo "Message sent! Thanks ! ";
print('<a href="xu/mail/form.html">Reset and Back</a>');
}
?>
email.php
<?php
$message = '
Hello '.$name.', <br/>
we have received your interest in child care services for '.$childname.' from the '.$site.' website. <br/>
<br/>
'.$days.'
<br/> <br/>
Should you have any questions regarding the information on our enrolment form or services please do not hesitate to contactkkk
<br/> <br/> <br/>
Regards, <br/>
<a href="mailto:[email protected]">[email protected]</a> <a href="http://www.nx.com.au" target="_new">www.neo-it.com.au</a>
<br/>
<strong>Childcare Management Services</strong>
<br/> <br/>
'
?>
thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要在 PHP 中发送简单的邮件,您需要:
对于附加文件,您必须使用
multipart
Content-Type因此,您可以编写一个接受所需变量的自定义函数,并发送两封邮件 - 一封是您想要发送带有附件的邮件的邮件,另一封是发送到另一个不带附件的电子邮件 ID 以进行记录保存。
For sending a simple mail in PHP, you require:
For attaching files, you've to use
multipart
Content-TypeSo, you could write a custom function which accepts the variables required, and sends two mails - One where you want to send the mail with files attached, and the other to another email ID without attachments for Record Keeping.
我在帮助下这样做了
phpFreaks
非常简单!
谢谢怪胎!
I did it this way with the help
of phpFreaks
very simple!
thanks freaks!