构建一个php邮件与复制粘贴电子邮件地址文本区域(字段)


Building a php mailer with copy-and-paste email address textarea (field)

我是构建php邮件的新手。我已经建立了从地址,发件人的姓名,回复到,消息体和粘贴电子邮件(文本区)字段的形式。然而,问题在于脚本。我使用爆炸函数将粘贴电子邮件字段的值转换为数组。我使用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/,它将允许您传递一组"to"地址并发送到每个地址

相关文章: