How can i send data from sessions using PHPMailer?

Take a look at the syntax used in the examples

http://php.net/manual/en/session.examples.basic.php

I dont understand, please fix the script

Which part do you not understand?

Hint: You donā€™t want the round brackets.

In one post, you said this:

yet now, youā€™ve said this:

Can you see the difference? Which one of those two have you used? If youā€™ve used the first, it should be fine. If youā€™ve used the second pair, it wonā€™t work. Look at the difference between these lines, and the lines in the first quote in this post, or indeed your (working) use of session variables in your earlier posts. Theyā€™re not the same. I know itā€™s only a minor difference, but details like this are the difference between right and wrong.

You have a misunderstanding of how forums work. I am presuming English is not your first language and your repeated demands for someone to do your work for you is just down to poor translation.

2 Likes

which round brackets?

Look at my post above, you must be able to see the difference between the two quotes from your code?

i used
$name=$_SESSION[ā€˜sessnameā€™];
$message=$_SESSION[ā€˜sessmessageā€™];

not working PHPMailer says
Notice: Undefined index: sessmessage in /home

i have fixed it properly with this
$name=$_SESSION[ā€˜sessnameā€™];
$message=$_SESSION[ā€˜sessmessageā€™];

PHPMailer is now working fine and able to send message to my email address, but dont send the data that it needs to send. i.e the name and the message

what am i not doing right?

Post the current code, exactly as it is now.

have a look at the actual contents of these variables with var_dump

http://php.net/manual/en/function.var-dump.php

<?php session_start(); ?>
<?php

$name=$_SESSION['sessname'];
$message=$_SESSION['sessmessage'];

require 'PHPMailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer();

$mail->IsSMTP();     // set mailer to use SMTP
$mail->Host = "mail.mydomainname.com";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "info@mydomainname.com";  // SMTP username
$mail->Password = "12345678"; // SMTP password

$mail->From = "info@mydomainname.com";
$mail->FromName = "mydomainname.com";
$mail->AddAddress("info2@mydomainname.com", "info2");

$mail->WordWrap = 50;  // set word wrap to 50 characters

$mail->Subject = "message enquiry";
$mail->Body    = "Name: $name\nMessage: $message;



if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

header( "Location: https://mydomainname.com" );
?>

Iā€™m amazed that this bit of code:

$mail->Body    = "Name: $name\nMessage: $message;



if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

results in a message being sent. Do you see anything missing from the end of the first line in that section, or is it a copy/paste error when you copy the code to the forum?

i have used that code to send messages several times, it is working fine, the problem is how to collect data to be sent

Where are you setting your session variables?

This is the message that was sent to my email address with the PHPMailer script
Name:
Message:
Message sent from computer IP: 0.0.0.0

The IP was successfully sent , but the name and message was not sent.

In PHPMailer

<?php session_start(); ?>
<?php

$name=$_SESSION['sessname'];
$message=$_SESSION['sessmessage'];

require 'PHPMailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer();

$mail->IsSMTP();     // set mailer to use SMTP
$mail->Host = "mail.mydomainname.com";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "info@mydomainname.com";  // SMTP username
$mail->Password = "12345678"; // SMTP password

$mail->From = "info@mydomainname.com";
$mail->FromName = "mydomainname.com";
$mail->AddAddress("info2@mydomainname.com", "info2");

$mail->WordWrap = 50;  // set word wrap to 50 characters

$mail->Subject = "message enquiry";
$mail->Body    = "Name: $name\nMessage: $message;



if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

header( "Location: https://mydomainname.com" );
?>

That looks like the code you have already posted. I donā€™t see how or where it answers my question.

i want to set it in my PHPMailer script so i can be able to send the data to my email address.

the error is coming from here
$name=$_SESSION[ā€˜sessnameā€™];
$message=$_SESSION[ā€˜sessmessageā€™];

That is extracting the values from the $_SESSION array. In order to extract values, you first have to put something in there.