Justin Yoder
Justin Yoder

Reputation: 537

emailing using phpmailer using post data for email address

im trying to email something to a user based on the email address that is entered on the html form. i am using post as the method and i cant figure out how to use that data for the email address using phpmailer.

<!DOCTYPE html>
<html>
<form method='post'>
<input type='email' value='@domain.com' name='emailaddress'>
<input type='submit' value='submit' name='submit'> 
</form>
</html>
<?php
if (isset($_REQUEST['Submit'])) {
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail-> IsSMTP();
$mail->Host = "mail.domain.com";

$mail->Username = 'username';
$mail->Password = 'password';
$mail->From = "[email protected]";
$mail->FromName = "foo bar";
$mail->AddAddress = (HERE IS WHERE I WANT TO ENTER emailaddress FROM THE FORM);
$mail->Subject = "test1";
$mail->Body = "Test 1 of PHPMailer.";
$mail->IsHTML(true);
$mail->Port = 25;
$mail->AddAttachment('sample.pdf','sample.pdf');
//$mail->SMTPSecure = 'ssl';
if(!$mail->Send())
{
echo "Message did not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";


}
?>

Upvotes: 1

Views: 3329

Answers (1)

SynerCoder
SynerCoder

Reputation: 12786

form edit:

<input type='email' value='@domain.com' name='emailaddress'>

(removed the double quote)

php edit:

$mail ->AddAddress = $_POST['emailaddress'];

should do the job.

Upvotes: 3

Related Questions