Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

php $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
Oliver Gibbs
9,771 Points

It 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