2011-11-22 101 views
1

我是構建php郵件的新手。我使用FROM ADDRESS,SENDER'S NAME,REPLY-TO,MESSAGE BODY和PASTE EMAIL(textarea)字段構建了表單。然而,問題在於腳本。我使用爆炸函數將PASTE EMAIL字段的值轉換爲數組。我使用array_walk函數,但我似乎沒有得到正確的。我需要一個可以從這個數組中選擇每個電子郵件地址並將消息副本發送給它的函數。 見下面我的腳本:使用複製粘貼電子郵件地址構建一個php郵件textarea

<?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 = "[email protected]"; 
    $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); 

} 

?> 

我不包括這裏的形式。如果有人能幫助我,我會很感激。

+0

你有什麼錯誤嗎?快速查看錶明,您不是在'function_to_be_applied()'中使用的所有東西,比如'$ replyto','$ seconds'等等。嘗試添加它們,看看它是否有幫助。 – jprofitt

+1

請考慮重新考慮您的代碼。 – Flukey

回答

1

對於我所有的PHP郵件需求,我使用http://swiftmailer.org/它將允許您傳遞一個「到」地址數組併發送給它們中的每一個。

+0

jprofitt,非常感謝。這解決了問題 –

相關問題