/    Sign up×
Community /Pin to ProfileBookmark

phpmailer not sending email

I am trying to have a form with 2 steps. I want to have the info from form 1 send to an email even when the user did not complete the 2nd form. 2nd form is posting other info and will take the user to thank you page when completed.I have the below script. It takes me to the 2nd form, there is no error message but it is not sending the email to me.

[CODE]<?php
session_start();
require_once(“class.phpmailer.php”);

$errors = array();
if (‘POST’ === $_SERVER[‘REQUEST_METHOD’])
{
$salutation = sanitize($_POST[‘salutation’]);
$fname = sanitize($_POST[‘fname’]);
$lname = sanitize($_POST[‘lname’]);
$email = sanitize($_POST[’email’]);

if (empty($fname))
{
$errors[‘fname’] = “First’s name cannot be empty.”;
}
if (empty($lname))
{
$errors[‘lname’] = “last’s name cannot be empty.”;
}

if (count($errors) === 0)
{
include(“config.php”);

$message = ‘
Name: ‘.salutation.’ ‘.$fname.’ ‘.$lname.’
Email: ‘.$email.'<br>
‘;

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘ssl’;
$mail->Host = $host;
$mail->Port = $port;
$mail->Username = $User;
$mail->Password = $PWD;
$mail->SetFrom($email, $fname . ” ” . $lname);
$mail->AddAddress(’[email protected]’);

$mail->Subject =’Test’;
$mail->Body = $message;
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Send();

exit(header(“Location:page2.php”));

}}

function sanitize($value)
{
return trim(strip_tags($value));
}

?>
[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 21.2015 — First find out if you even get to that point with whatever debugging technique works for you (e.g. a simple [b]die("HERE"):[/b] to find out if you made it to that point in the code. If it's getting to the mail send() method, then check to see if it returns false, and if so, get some debug info (e.g. see the end of this example). If it thinks it is, in fact, sending it, then be sure to check your spam folder for the recipient to see if it's ending up there for some reason.
×

Success!

Help @phpnewbie08 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...