使用复制粘贴电子邮件地址textarea(字段)构建php邮件程序

时间:2011-11-22 13:35:19

标签: php

我是构建php邮件的新手。我已经使用FROM ADDRESS,SENDER'S NAME,REPLY-TO,MESSAGE BODY和PASTE EMAIL(textarea)字段构建了表单。然而,问题是脚本。我使用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);

}

?>

我这里没有包含表格。如果有人可以帮助我,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

对于我所有的PHP邮件需求,我使用http://swiftmailer.org/它将允许您传递一个“to”地址数组并发送给每个人。