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 trialbyungrok yoo
360 Pointsphp $address = "";
<?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("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->IsSMTP();
$mail->SMTPAuth = true;
$mail -> SMTPDebug = 2;
$mail->Host = "smtp.daum.net";
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
$mail->Username = "pupabu";
$mail->Password = "***********";
$mail->SetFrom($email, $name);
$address = "pupabu@paran.com";
$mail->AddAddress($address, "Wishaw Guitar Lessons");
$mail->Subject = "Shirts 4 Mike Contact Form Submission | " . $name;
$mail->MsgHTML($email_body);
if($mail->Send()) {
header("Location: contact.php?status=thanks");
exit;
} else {
$error_message = "There was a problem sending the email: " . $mail->ErrorInfo;
}
}
}
i happend to erro "There was a problem sending the email: You must provide at least one recipient email address." T_T plz help me
1 Answer
Oliver Gibbs
9,771 PointsIt looks like at the start of your code the email address is stored in a variable called $email, but later you reference it as $address.
Try changing this line:
$mail->AddAddress($address, "Wishaw Guitar Lessons");
and change $address to $email