php - PHPMailer get addresses from file -
i'm trying get addresses simple text file, people don't understand code can still add/remove or change adresses.
phpmailer working totally fine when set address normally, writing directly in code, , array , foreach.
so @ moment have :
mail.php :
//all phpmailer settings on $mail var $addresses = file('mail.txt', file_ignore_new_lines); foreach($addresses $email) { echo "$email<br>"; $mail->addaddress($email); }
mail.txt :
'first@address.com' 'second@address.fr'
the echo return both addresses var doesn't seem work in addaddress() line, , usual error : mailer error: must provide @ least 1 recipient email address.
thanks correcting me if i'm wrong or if know other solution work !
okay here working code corrected of waqas shahid :
mail.php :
//all phpmailer settings on $mail var $addresses = file('mail.txt', file_ignore_new_lines); foreach($addresses $email) { $email = trim($email); $change = array('\n', '\t', '\r'); $email = str_replace($change, "", $email); $mail->addaddress($email); }
mail.txt :
first@address.com second@address.fr
you should remove single quotes first, value line line , remove whitespaces using trim()
remove '\n', '\t', '\r' using str_replace()
Comments
Post a Comment