LondonMaker Posted June 19, 2018 Share Posted June 19, 2018 Below is the code I am using to send an email with an attachment, what I want is the send to email be an email that is registered as a php session variable, what am I doing wrong? Thanks Tim <? session_start(); ?> <? $semail = $_SESSION["email"]; ?> <?php /** * This example shows sending a message using PHP's mail() function. */ //Import the PHPMailer class into the global namespace use PHPMailer\PHPMailer\PHPMailer; require 'vendor/autoload.php'; //Create a new PHPMailer instance $mail = new PHPMailer; //Set who the message is to be sent from $mail->setFrom('from@example.com', 'First Last'); //Set an alternative reply-to address $mail->addReplyTo('replyto@example.com', 'First Last'); //Set who the message is to be sent to $mail->addAddress('$semail', 'John Doe'); //Set the subject line $mail->Subject = 'PHPMailer mail() test'; //Read an HTML message body from an external file, convert referenced images to embedded, //convert HTML into a basic plain-text alternative body $mail->msgHTML('This is message body'); //Replace the plain text body with one created manually $mail->AltBody = 'Just a test'; //Attach an image file $mail->addAttachment('perks/pizzaperk.png'); //send the message, check for errors if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 19, 2018 Share Posted June 19, 2018 Whatever are you trying to say with this line? what I want is the send to email be an email that is registered as a php session variable That line makes absolutely no sense to me. You want an email to be saved as a session var? Do you mean the body of the email? Or do you mean the whole phpmailer construct? And why? How about you ask a question and see what suggestion you get back on how to accomplish your goal? Quote Link to comment Share on other sites More sharing options...
Barand Posted June 19, 2018 Share Posted June 19, 2018 (edited) Quote $mail->addAddress('$semail', 'John Doe'); The single quotes around the variable are treating it as a literal string, and not a value $var = 'Some text' echo $var; //--> Some text echo '$var'; //--> $var Edited June 19, 2018 by Barand Quote Link to comment Share on other sites More sharing options...
maxxd Posted June 19, 2018 Share Posted June 19, 2018 (edited) You've got single quotes around $semail in your setAddress() call. PHP doesn't parse variables inside single quotes - remove them. And Barand beat me to it... Edited June 19, 2018 by maxxd Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.