Jump to content

Cant put php session email into mail send code what am I doing wrong?


LondonMaker

Recommended Posts

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!";
}
?> 

 


 
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.