简体   繁体   中英

Sending Multiple E-Mail PHP

Well guys, I'm trying to send multiple emails with different contents. but it doesn't work properly and I think I already stuck on this @_@. can you please help me find the problem?

well thx, sorry for the bad English.

$email = array('blazriku@gmail.com','henrikus.antony@gmail.com');
$subject = array("send message", "Welcome");
$message = array($_POST['Message'],);
$messages = implode(',',$message);
$name = array('Admin','Admin');
$to=$email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: kebunbibit.id <noreply@yourwebsite.com>'."\r\n" . 'Reply-To: '.$name.' <'.$email.'>'."\r\n";
$headers .= 'Cc: admin@yourdomain.com' . "\r\n"; //untuk cc lebih dari satu   tinggal kasih koma
for($i = 0; $i < count($message); $i++;){
    @mail($to, $subject[$i], $messages[$i], $headers);
}    
if(@mail)
{
print "<script>window.alert('E-Mail Terkirim!')</script>";  
print "<script>window.location='home.php?page=surat_jalan'</script>";    
}
else{
print "<script>window.alert('E-Mail Gagal Terkirim!')</script>";  
print "<script>window.location='home.php?page=surat_jalan'</script>";      
}

In the for-loop you have to get length from messages not the single message.

for($i = 0; $i < count($messages); $i++;){
    @mail($to, $subject[$i], $messages[$i], $headers);
}    

Maybe the 's' in the for-loop should fix your problem. Otherwise the failure maybe comes up later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM