0
votes
      <html> 
      <form method="post" action="email.php">
   Email: <input name="email name" id="email" type="text" /><br/>
      Message:<br/><text area name="message" id="message" rows="15" cols="40</text area><br>
       <input type="submit" value="Submit" />
       </form>
     <html/>

i have those code and i want to send email to [email protected] on a contact form but it says enter at least one recipient and when am entering email to $mail-> add address($email) if i change to $mail->addadress([email protected]) even if the email on a form is differ from default it will send to [email protected] please help me.

<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

require("PHPMailerAutoload.php");
require "class.phpmailer.php";

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->SMTPSecure = "tls"; 
$mail->Port       = 587;   

$mail->Host = "smtp.gmail.com";  
$mail->Username = "[email protected]";  // SMTP username
$mail->Password = "*************"; // SMTP password
$mail->AddAddress=$email;
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
$mail->Body    = $message;
$mail->AltBody = $message;

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>
1
addAddress is a function within the PHPMailer class so you need to pass the desired email as an argument.MonkeyZeus

1 Answers

2
votes

AddAddress is a method, not a property.

$mail->AddAddress=$email;

Should be:

$mail->AddAddress($email);