![](/img/trans.png)
[英]How to change from email address in smtp php mailer function sendmail()
[英]Building a php mailer with copy-and-paste email address textarea (field)
我是构建php mailer的新手。 我已使用“发件人地址”,“发件人的姓名”,“回复”,“邮件正文”和“粘贴电子邮件”(文本区域)字段构建了表单。 但是问题是脚本。 我使用了explode函数将PASTE EMAIL字段的值转换为数组。 我使用了array_walk函数,但似乎不正确。 我需要一个可以从此数组中选择每个电子邮件地址并将消息的副本发送给它的函数。 请参阅下面的脚本:
<?php
function function_to_be_applied($finaldest_email, $key){
require_once "Mail.php" ;
global $fromemail;
global $message;
global $fromname;
global $subject;
$to = $finaldest_email;
$from = "{$fromname} <$fromemail>";
$subject = $subject;
$host = "mail.mydomain.com";
$body = $message;
$smtp_username = "helpdesk@mydomain.com.com";
$smtp_password = "password111";
$header = array('From' => $from, 'To'=>$to, 'Subject'=>$subject, 'replyTo'=> $replyto);
$smtp = Mail::factory('smtp', array('host'=>$host, 'auth'=> true, 'username'=> $smtp_username, 'password' => $smtp_password, 'port' => 2626));
$mail = $smtp->send($to, $header, $body);
if(PEAR::isError($mail)){return true;}else{return false;}
sleep($seconds);
}
//Output from the form
$seconds = $_POST['seconds'];
$subject = trim($_POST['subject']);
$fromname = trim($_POST['fromemail']);
$fromemail = trim($_POST['fromemail']);
$message = trim($_POST['message']);
$replyto = trim($_POST['replyto']);
$dest_email = trim($_POST['dest_email']);
$emailarray = explode("\r\n", $dest_email, 200);
$finaldest_email = array_unique($emailarray );
//using array_walk() function
if( true == array_walk($finaldest_email, 'function_to_be_applied' )){
echo "Number of email sent: ".count($finaldest_email);
}
?>
我没有在这里包括表格。 如果有人可以帮助我,我将不胜感激。
对于我所有的PHP邮件需求,我都使用http://swiftmailer.org/ ,它将允许您传递一个“收件人”地址数组并将其发送给每个地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.