views:

32

answers:

4

I have a form I've created, and on completion they are asked to select person they want it emailed too from a drop down list.

My issue is how do I add that variable to the $mailer.

right now it is written like this

$mailer -> AddAddress('[email protected]','First Last');

how do i get my variable in there

$mailer -> AddAddress($emailAddress) - Doesn't work.

I've also tried

"'"$emailAddress"'" - this gives me - Invalid address: '[email protected]' which is frustrating since that's the format it is looking for.

Thanks, let me know

here is the full code that I am using to call the 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 the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password
$mail->AddReplyTo('[email protected]', 'First Last');
$mail->AddAddress('[email protected]', 'John Doe');
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo('[email protected]', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; //     optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif');      // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
A: 

Try doing an

var_dump($emailAddress);

right before the ->AddAddress() call and see what comes out. If you're doing this within a function, it's possible you've not passed $emailAddress in as a parameter, of forgotten to make it global;

As well, don't surround the email address with double quotes. It's not necessary:

$emailAddress = '[email protected]';  // correct
$emailAddress = "[email protected]"; // correct
$emailAddress = '"[email protected]"'; // incorrect
$emailAddress = "\"[email protected]\""; // incorrect.
Marc B
var_dump($emailAddress) - "[email protected]"And then is shows Address Invalid, I've found that it needs single quotes to actually accept the email as valid.This is where my issue is, since if I use single quotes I can no longer use the variable.
FixingGenie
What is the exact error message? There's only two places where "Invalid Address" could be output from phpmailer, a private method (`AddAnAddress()`), and a public method `SetFrom()`
Marc B
A: 

If $emailAddress came from a POST, use stripslashes around the value.

Make sure the select box has the correct value in the markup (check your view source).

As suggested, echo the variable to check it.

AutoSponge
I am converting the POST into a Global session, and then putting it into an array.From there I am calling the Session into a variable, and then echoing the variables.When I get the echo, it comes back fine. and when I try escaping with the slashes, i get the slashes in the actual variable.\'[email protected]\'
FixingGenie
I have my own mailer class. But, they all basically do the same thing: build a header, sanitize some variables, and call mail(). You can edit the $mail class to echo the recipients (the first argument of mail()).
AutoSponge
A: 

I got it to work, there was an issue in my values.

Actually there were a couple.

Lets just saying some spelling was incorrect.

Thanks for all the info though!

FixingGenie