/    Sign up×
Community /Pin to ProfileBookmark

How can i send data from sessions using PHPMailer?

I am using dreamweaver version 8 and i have used sessions to transfer data from my first page to the second page, but i want to send the data to my email address using php mailer, but i am stuck because I don’t know how to use phpmailer to send it.

FIRST PAGE
<?php session_start();?>
<title>Untitled Document</title>
</head>

<body>
<form id=”form1″ name=”form1″ method=”post” action=”2.php”>
<table width=”807″ border=”0″>

<td height=”75″></td>
<td height=”28″></td>
<td>Name:</td>
<td><label>
<input name=”name” type=”text” id=”name” />
</label></td>
<td><label>
<input type=”submit” name=”Submit” value=”Submit” />
</label></td>
</tr>
<tr>
<td height=”106″></td>

<td height=”110″></td>

</table>
</form>
</body>
</html>

2ND PAGE

<?php session_start();

$_SESSION[‘sessname’] = $_POST[‘name’];

?>

<body>
<form id=”form1″ name=”form1″ method=”post” action=”sendmail4.php”>
<table width=”644″ border=”0″>

<td>Message</td>
<td><label>
<textarea name=”message” id=”message”></textarea>
</label></td>

<td><a href=”3.php”>
<label>
<input type=”submit” name=”Submit” value=”Submit” />
</label>

</table>
</form>
</body>
</html>

SENDMAIL

<?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 = “[email protected]“; // SMTP username
$mail->Password = “12345678”; // SMTP password

$mail->From = “[email protected]“;
$mail->FromName = “mydomainname.com”;
$mail->AddAddress(“[email protected]“, “info2”);

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

$mail->Subject = “message enquiry”;
$mail->Body = “Name: $namenMessage: $message;

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

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

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 26.2017 — Are you getting any error messages? If so, let us know what they are. If not, add the following at the start of each PHP script (at least for now while debugging):
[code=php]
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
// rest of script . . .
[/code]
Copy linkTweet thisAlerts:
@james2020authorJul 26.2017 — Are you getting any error messages? If so, let us know what they are. If not, add the following at the start of each PHP script (at least for now while debugging):
[code=php]
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
// rest of script . . .
[/code]
[/QUOTE]


i have included your script below <?php session_start(); ?>

i think the problem is this

$name=$_SESSION(['sessname']);

$message=$_
SESSION(['sessmessage']);

PHPMailer says Fatal error: Function name must be a string in /home/t3w00j6/public_html/sendmail4.php on line 8

and line 8 is

$name=$_SESSION(['sessname']);

$message=$_
SESSION(['sessmessage']);

how can do it?
Copy linkTweet thisAlerts:
@james2020authorJul 26.2017 — 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
Copy linkTweet thisAlerts:
@ginerjmJul 26.2017 — So - Where are those session elements being set? Are you sure they have the values you expect? Do a display of them before you do the email to debug it.
Copy linkTweet thisAlerts:
@NogDogJul 26.2017 — So - Where are those session elements being set? Are you sure they have the values you expect? Do a display of them before you do the email to debug it.[/QUOTE]

It was just a syntax issue, which s/he resolved by removing the incorrect parentheses around the bracketed array indexes (after turning on error reporting to find out where the problem was ? ).
Copy linkTweet thisAlerts:
@ginerjmJul 26.2017 — I know. I am assuming that he doesn't have any values in those elements and wondered if he did any debugging to check.
×

Success!

Help @james2020 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...