php - Using PHPMailer to send emails to Variable addresses -


i have form i've created, , on completion asked select person want emailed drop down list.

my issue how add variable $mailer.

right written this

$mailer -> addaddress('email@email.com','first last'); 

how variable in there

$mailer -> addaddress($emailaddress) - doesn't work. 

i've tried

"'"$emailaddress"'" - gives me - invalid address: 'email@email.com' frustrating since that's format looking for.

thanks, let me know

here full code using call emails

$mail->host       = "mail.yourdomain.com"; // smtp server $mail->smtpdebug  = 2;                     // enables smtp debug information (for testing) $mail->smtpauth   = true;                  // enable smtp authentication $mail->host       = "mail.yourdomain.com"; // sets smtp server $mail->port       = 26;                    // set smtp port gmail server $mail->username   = "yourname@yourdomain"; // smtp account username $mail->password   = "yourpassword";        // smtp account password $mail->addreplyto('name@yourdomain.com', 'first last'); $mail->addaddress('whoto@otherdomain.com', 'john doe'); $mail->setfrom('name@yourdomain.com', 'first last'); $mail->addreplyto('name@yourdomain.com', 'first last'); $mail->subject = 'phpmailer test subject via mail(), advanced'; $mail->altbody = 'to view message, please use html compatible email viewer!'; //     optional - msghtml create alternate automatically $mail->msghtml(file_get_contents('contents.html')); $mail->addattachment('images/phpmailer.gif');      // attachment $mail->addattachment('images/phpmailer_mini.gif'); // attachment $mail->send(); 

try doing an

var_dump($emailaddress); 

right before ->addaddress() call , see comes out. if you're doing within function, it's possible you've not passed $emailaddress in parameter, of forgotten make global;

as well, don't surround email address double quotes. it's not necessary:

$emailaddress = 'email@email.com';  // correct $emailaddress = "email@email.com"; // correct $emailaddress = '"email@email.com"'; // incorrect $emailaddress = "\"email@email.com\""; // incorrect. 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -