/    Sign up×
Community /Pin to ProfileBookmark

phpmailer how to send auto-respond after user submission

Hello I’m pretty new to phpmailer I wanted to know if anyone knows how to have to user get a thank you email after submitting a form in phpmailer:

here is how i got it working – right now the user submits and gets a thank you page but also wanted them to get an email thank you too here’s the end function that makes it work to tell me i got the new lead:

[CODE]
$mail = new PHPMailer();

include_once ‘settings.php’;

$mail->MsgHTML($email_body);

if(!$mail->Send())
{
echo “Mailer Error: ” . $mail->ErrorInfo;
}

}
?>
[/CODE]

The settings.php is this:

[CODE]
$mail->SetFrom(‘[email protected]’, ‘me’);
$mail->Subject = $subject;

$mail->AddAddress(‘[email protected]’);
[/CODE]

Obviously if i just add another line like this:

[CODE]
$mail->MsgHTML($email_body);
$mail->MsgHTML(“<p>Thank you.</p> “);
[/CODE]

means [B]I[/B] will get the thank you note because of the settings….but how can i have this message be sent to the user that imputs his email?

Thanks

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 11.2011 — The user would have to provide you their email address as part of the form data, and you would then use that (from the $_POST array) with the AddAddress() method.
Copy linkTweet thisAlerts:
@riskmodauthorFeb 12.2011 — The user would have to provide you their email address as part of the form data, and you would then use that (from the $_POST array) with the AddAddress() method.[/QUOTE]

The user does provide the email i even get the results through the my db/email like this:

[CODE]
mysql_query($sql, $dd);

$subject = "New inquiry";
$message = "<b>New request</b><br />
<b>Name</b>: $first_name $last_name<br />
<b>Email</b>: $email<br />

$spam = array("FROM:", "TO:", "CC:", "CCO:", "BCC:", "Content-Type");
[/CODE]


So would i have to add that in the settings? or I was assuming to add it after this:

[CODE]
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
[/CODE]


Thanks
Copy linkTweet thisAlerts:
@NogDogFeb 12.2011 — You have to add it at any time after you do [b]$mail = new PHPMailer();[/b] and before you do the [b]$mail->Send()[/b]. Other than that, it doesn't really matter, just whatever works for you.
Copy linkTweet thisAlerts:
@riskmodauthorFeb 13.2011 — You have to add it at any time after you do [b]$mail = new PHPMailer();[/b] and before you do the [b]$mail->Send()[/b]. Other than that, it doesn't really matter, just whatever works for you.[/QUOTE]

Right but you said put:

(from the $_POST array) with the AddAddress()

Where do i put that?
Copy linkTweet thisAlerts:
@NogDogFeb 13.2011 — [code=php]
$mail->AddAddress($email);
[/code]

Just put that anywhere after the point where you define [b]$email[/b] and before you do the send().
Copy linkTweet thisAlerts:
@riskmodauthorFeb 14.2011 — [code=php]
$mail->AddAddress($email);
[/code]

Just put that anywhere after the point where you define [b]$email[/b] and before you do the send().[/QUOTE]


So I do it like this:

[CODE]
$mail = new PHPMailer();

include_once 'settings.php';

$mail->MsgHTML($email_body);
$mail->AddAddress($email, "<p>Thank you.</p> ");

if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}

}
?>

[/CODE]


This is the confusing part because I want the:

$mail->MsgHTML($email_body); sent to me and

$mail->AddAddress($email, "<p>Thank you.</p> "); to the user.


How can this be done at the same time because after putting that the user gets the the MsgHTML($email_body) which I don't want that.

Thanks so much NogDog!
Copy linkTweet thisAlerts:
@riskmodauthorFeb 14.2011 — heh i resolved this i figure what you mean NogDog.

Basically I had to do [B]2 intances![/B] one for me the admin and the other for the user.....wow that simple....THANK YOU NOGDOG!
Copy linkTweet thisAlerts:
@jeeva_kaphilOct 19.2019 — @riskmod#1138978 Please tell me clearly i have to add settings.php file in the project

$mail->setFrom(' [email protected]', 'dummy');

$mail->addAddress('[email protected]', 'Sample');

$mail->MsgHTML($email_body);

$mail->addAddress($email, "<p>Thank you.</p>"); // Add a recipient

This Code i have added in my php code but its working
×

Success!

Help @riskmod 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 4.26,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...