my php email for is sending emails every time the page is refreshed. For example the user is filling out the form and sending it with the send button. That\'s all fine and g
try this-
require_once('class.phpmailer.php');
if(isset($_POST['submit'])){
$name = $_POST['name'];
$subject = 'WebForm';
$email = $_POST['email'];
$body = $_POST['message'];
$mail = new PHPMailer;
// $mail->SMTPDebug = 2;
// print_r($_POST);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.office365.com";
$mail->Port = 587;
$mail->Username = "person@emailaddy.com";
$mail->Password = "password";
$mailto = "person@emailaddy.com";
$mailfrom = "person@emailaddy.com";
$mail->SetFrom($mailto, '');
// $mail->AddReplyTo($mailfrom, 'email');
$address = 'person@emailaddy.com';
$mail->AddAddress($address, "My Addy");
$mail->Subject = $subject;
$mail->AltBody = $body;
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo 'Message has been sent';
}
}
the mail
sending function was outside of the if condition with $_POST
check. So it was sending mail everytime it is refreshed.