Ricky55 Posted February 24, 2015 Share Posted February 24, 2015 Hi guys Hoping you can help me with this. I'm very much a front end person, I know HTML, CSS and some JS but when it comes to PHP and very much a newbie. I'm using this code to process a straight forward contact form. I'm using the PHP Mailer as I need to use an external smtp server and the company I use for this provided some basic code. Its working but I'm getting a error flash up before I see the success page that says "Undefined variable: message in send.php on line 25. Why is this happening and how do I fix it? Thanks guys. my code <?php require("PHPMailerAutoload.php"); // path to the PHPMailer class. $after = "/contact/thanks.php"; $oops = "/contact/error.php"; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Mailer = "smtp"; $mail->Host = "smtpcorp.com"; $mail->Port = "2525"; $mail->SMTPAuth = true; $mail->Username = "name@hotmail.com"; $mail->Password = "xxx"; $mail->From = "name@hotmail.com"; $mail->FromName = "Richard Dale"; $mail->AddAddress("name@hotmail.com", "Rachel Recipient"); $mail->AddReplyTo("name@hotmail.com", "Sender's Name"); $mail->Subject = "Contact enquiry from the website"; $message .= "How can we help: {$_POST['help']} \n\n"; $message .= "Name: {$_POST['name']} \n\n"; $message .= "Email: {$_POST['email']} \n\n"; $message .= "Telephone: {$_POST['tel']} \n\n"; $message .= "Message: {$_POST['message']} \n\n"; $message .= "Address: {$_POST['address']} \n\n"; $mail->Body = $message; $mail->WordWrap = 50; if(!$mail->Send()) { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">"; } else { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/294860-help-with-php-mailer-contact-form-undefined-variable/ Share on other sites More sharing options...
Solution maxxd Posted February 24, 2015 Solution Share Posted February 24, 2015 The first time you use $message, it's not defined yet, so you can't concatenate (the period is a concatenation operator if PHP). So, where you've got $message .= "How can we help: {$_POST['help']} \n\n"; Should be either $message = "How can we help: {$_POST['help']} \n\n"; or $message = ""; $message .= "How can we help: {$_POST['help']} \n\n"; Quote Link to comment https://forums.phpfreaks.com/topic/294860-help-with-php-mailer-contact-form-undefined-variable/#findComment-1506588 Share on other sites More sharing options...
Ricky55 Posted February 24, 2015 Author Share Posted February 24, 2015 Unbelievable!!!! spent about an hour messing about with that. Thanks very much!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/294860-help-with-php-mailer-contact-form-undefined-variable/#findComment-1506590 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.