php - how to send email to multiple recipients using textarea box? -
i send email multiple recipients using below code has problem. first have set emails on php code ($to="email,email,email more"). can send them email.
i wants text area box () paste email/email list , send them. don't want add email 1 one on php code.
this code:
<?php $to = $_post['email_list']; //i'm trying not working. //$to = "xyz@somedomain.com".","."xyz1@somedomain.com".","."xyz2@somedomain.com"; $subject = $_post['subject']; $message = $_post['message']; $header = "from:abc@somedomain.com \r\n"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) { echo "message sent successfully..."; }else { echo "message not sent..."; } ?> <textarea type="text" name="email_list"></textarea><br/> <input type="text" name="subject"/><br/> <textarea type="text" name="message"></textarea><br/> <input type="submit" name="submit" value="submit"/>
if want build list of email recipients, can use explode()
list of emails array, , use implode()
them single string comma delimiter.
for example, if have textarea email address seperated new line character (one email per line), can use php's php_eol
delimiter.
// submited email addresses array $email_list = explode(php_eol, $_post['email_list']); // implode array comma-delimited string $to = implode(",", $email_list);
if need be, run $email_list
through foreach
loop or array_walk
first, if want validate email addresses, etc.
edit: see answer: explode php string new line.
rather relying on php_eol, may best use regular expression \r , \n. reason being eol system (server) dependent, while actual line break character(s) come end user's browser, uses their operating system's eol.
Comments
Post a Comment