I am using dreamweaver and i have used sessions to transfer data from my first page to the 2nd page, but i want to send the data to my email address using php mailer, but im stuck because cant get how to use phpmailer to send it.
<?php session_start(); ?>
<?php
// $email and $message are the data that is being
// posted to this page from our html contact form
$name=$_POST($_SESSION['sessname']);
$message=$_POST($_SESSION['sessmessage']);
// When we unzipped PHPMailer, it unzipped to
// public_html/PHPMailer_5.2.0
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" );
?>
@taylor85p: when you post code on the forums, you need to format it so it will display correctly.
You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.
is not correct. Do you want the $_POST variables, or the $_SESSION variables? You’ve used both in the earlier code correctly, then done it wrong in the last bit.
i don’t know where to use the $_POST or $_SESSION variable here, i only want after the visitor enter his/her email and message and submit, the message goes to my email using PHPMailer, please review and help, and send the correct code and where to place the code. thanks
Do i also need the 3.php (3rd page)? or is it just the first and second page i need? because i would want the email to be sent after the visitor enters the message. hope you understand me?
Well, you could start by using the same syntax you’ve used in the other bits of code, rather than combining them in this way. Look at how you retrieved the session variables to display them in the form in 3.php, and compare that to how you’ve tried to retrieve them in sendmail.php and see the difference.
That’s up to you. I must admit I did wonder why you ask for one thing in the first page, another thing on the second page, then ask for them both again on the third page, and then send the message. Why don’t you just put all the form variables in a single form on a single page, and send that directly to sendmail.php?
No, sorry - I’m happy to try to help, but I’m not just going to do it for you.
OK, but you’ve made progress - it may well still not be working, but it’s failing differently now. Presumably you’ve checked that the form variables are coming through correctly and that the message is correctly formed, so you know that the forms and your session variable handling is working, so you can forget about that bit unless you decide to streamline it into a single form. Only thing is, doing that won’t help you learn about session variables.
All you have to do now is fix whatever is wrong with your PHPMailer setup, which I can’t help with because I’ve never used it.
You’re missing SMTPSecure and the port. You need to figure out what the SMTP server offers as the outgoing mails as port and what kind of encryption they offer. It’s either tls or ssl. But if the SMTP server doesn’t offer ssl, you won’t be able to use it even if you want to so your next choice would be tls.
That’s because you are writing it wrong. You’re wrapping those variables around parentheses which means that they are being called as a function hence your error message. It’s saying that functions have to have string names. You can’t use PHP variables as a function name.
If you are trying to assign and create those variables, you should always do it left to right and not right to left because it will confuse you even more when you try to write code. What I am basically saying is, you should make the assignments on the left side and whatever you are appending to the assigned variables on the right. Most people write code like this and not the way you are doing it.