Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCRYSTAL MORRIS
Courses Plus Student 2,809 PointsI Tried To Define These On My Seperate Forms Page And It Wrecked Everything
Notice: Undefined variable: email in C:\xampp\htdocs\WINCHER MUSIC PUBLISHING\maggiewincher.com\contact-thanks.php on line 46
Notice: Undefined variable: name in C:\xampp\htdocs\WINCHER MUSIC PUBLISHING\maggiewincher.com\contact-thanks.php on line 47
Notice: Undefined variable: body in C:\xampp\htdocs\WINCHER MUSIC PUBLISHING\maggiewincher.com\contact-thanks.php on line 49 Message body empty
Am Trying To Send A Test Email To Myself
<?php include('includes/header.php'); ?>
<?php include('includes/style.php'); ?>
<?php ($_SERVER["REQUEST_METHOD"] = "POST"); ?>
<?php
foreach( $_POST as $value ){
if( stripos($value,'Content-Type:') !== FALSE ){
echo "There Was A Problem With The Information You Entered.";
exit;
}
}
require("includes/phpmailer/class.phpmailer.php");
$mail = new PHPMailer(true);
?>
<?php
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "mail.dreamhost.com"; // SMTP server
$mail->Username = "dreamhost.com"; // SMTP server username
$mail->Password = "b3GvEfR!"; // SMTP server password
$mail->IsSendmail(); // tell the class to use Sendmail
$to = "cemcorp@hotmail.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
$mail->From = "$email";
$mail->FromName = "$name";
$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>
<div class="section page">
<body>
<div class="container clearfix">
<p id="contact-thanks.php"></p><br>
<fieldset>
<legend align="center"><h2>Enjoy Your Day</h2></legend>
<h1>Thanks for completing the form! I'll be in touch shortly. </h1>
</fieldset>
<br>
<br>
<table>
<tr style="display: none;">
<th>
<label for="address">address</label>
</th>
<td>
<input type="text" Name="address" id="address">
</td>
</tr>
</table>
<br>
<a href="index.php" class="btn"><em>Home</a></em><br>
<br>
<br>
<?php include('includes/copyright.php'); ?>
</div>
5 Answers
Tong Vang
9,926 PointsCheck lines 46, 47, & 49. It says you have variables not defined. It seem you tried to give <p> an 'id' attribute that it can not have. It can only have "align" as attributes with <p>. That threw off all your codes from there.
CRYSTAL MORRIS
Courses Plus Student 2,809 PointsThanks Tong :-)
CRYSTAL MORRIS
Courses Plus Student 2,809 PointsTong Do You Know How To Fix This???
Tong Vang
9,926 Points<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
if ($name == "" OR $email == "" OR $message == "") {
$error_message = "You must specify a value for name, email address, and message.";
}
if (!isset($error_message)) {
foreach( $_POST as $value ){
if( stripos($value,'Content-Type:') !== FALSE ){
$error_message = "There was a problem with the information you entered.";
}
}
}
if (!isset($error_message) && $_POST["address"] != "") {
$error_message = "Your form submission has an error.";
}
require_once(ROOT_PATH . "inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if (!isset($error_message) && !$mail->ValidateAddress($email)){
$error_message = "You must specify a valid email address.";
}
if (!isset($error_message)) {
$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message;
$mail->SetFrom($email, $name);
$address = "orders@shirts4mike.com";
$mail->AddAddress($address, "Shirts 4 Mike");
$mail->Subject = "Shirts 4 Mike Contact Form Submission | " . $name;
$mail->MsgHTML($email_body);
if($mail->Send()) {
header("Location: " . BASE_URL . "contact/?status=thanks");
exit;
} else {
$error_message = "There was a problem sending the email: " . $mail->ErrorInfo;
}
=,
}
}
This is what I have for a project. This goes before the body of the page. Make sure your variables matches and replace anything about Shirst4Mike with your info. In the require_once line use your location for the phpMailer. Give it a try
Tong Vang
9,926 PointsIgnore the "=," at the end. Its a typo.
CRYSTAL MORRIS
Courses Plus Student 2,809 PointsCRYSTAL MORRIS
Courses Plus Student 2,809 PointsThis Is The Prayer Request Form