Php 如何在电子邮件成功发送后插入数据
我收到了问题需要帮助..几乎整整一天我都这么做了,但不知道怎么做..我得到了一个带有发送电子邮件和自动回复功能的联系表单..但我需要添加更多功能,比如在成功发送电子邮件后能够插入数据库..我附加了脚本 contact.htmlPhp 如何在电子邮件成功发送后插入数据,php,ajax,email,phpmailer,Php,Ajax,Email,Phpmailer,我收到了问题需要帮助..几乎整整一天我都这么做了,但不知道怎么做..我得到了一个带有发送电子邮件和自动回复功能的联系表单..但我需要添加更多功能,比如在成功发送电子邮件后能够插入数据库..我附加了脚本 contact.html <form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="contact_form" class="hubungi"> <input name="idContac
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="contact_form" class="hubungi">
<input name="idContact" type="hidden" value="" />
<div id="mail_success" class="success"><img src="success.png" />Thanks..</div>
<div id="mail_fail" class="error"><img src="error.png" /> Sorry, we don't know what happened. Please try again later.</div>
<!-- sini-->
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Bahagian</td>
<td><div class="inner-table">
<div class="left">
<select name="topic" id="topic">
<option value="">Please select a topic...</option>
<option value="op1">op2</option>
<option value="op2">op3</option>
</select>
</div>
<div class="right">
<div id="topic_error" class="error"><img src="error.png" /> What category should this be filed in?</div>
</div>
<div class="clear"></div>
</div></td>
</tr>
<tr>
<td>Nama</td>
<td><div class="inner-table">
<div class="left">
<input class="contact_name" type="text" name="name" id="name" />
</div>
<div class="right">
<div id="name_error" class="error"><img src="error.png" /> What category should this be filed in?</div>
</div>
<div class="clear"></div>
</div>
</tr>
<tr>
<td>Email</td>
<td><div class="inner-table">
<div class="left">
<input class="contact_email" type="text" name="email" id="email" />
</div>
<div class="right">
<div id="email_error" class="error"><img src="error.png" /> What category should this be filed in?</div>
</div>
<div class="clear"></div>
</div></td>
</tr>
<tr>
<td>Subjek</td>
<td><div class="inner-table">
<div class="left">
<input class="contact_subject" type="text" name="subject" id="subject" />
</div>
<div class="right">
<div id="subject_error" class="error"><img src="error.png" /> What category should this be filed in?</div>
</div>
<div class="clear"></div>
</div></td>
</tr>
<tr>
<td>Mesej</td>
<td><div class="inner-table">
<div class="left">
<textarea class="contact_message" name="message" id="message" ></textarea>
</div>
<div class="right">
<div id="message_error" class="error"><img src="error.png" /> What category should this be filed in?</div>
</div>
<div class="clear"></div>
</div></td>
</tr>
</table>
<!-- sini tamat-->
<div id="cf_submit_p">
<input class="submit" type="submit" id="send_message" value="Send Message">
</div>
</form>
仅发送PHP电子邮件
<?php
$autoResponse = true; //if set to true auto response email will be sent, if you don't want autoresponse set it to false
$autoResponseSubject = "Demo Contact Form";
$autoResponseMessage = "Hi, thank you testing the JQuery Contact Form Demo.";
$autoResponseHeaders = "From: email_from@yourWebsite.com";
//we need to get our variables first
$email_to = 'some@mail.com'; //the address to which the email will be sent
$topic = $_POST['topic'];
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['message'];
$message = "From: $name \r\nEmail: $email \r\nTopic: $topic \r\nMessage: \r\n$msg";
/*the $header variable is for the additional headers in the mail function,
we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
That way when we want to reply the email gmail(or yahoo or hotmail...) will know
who are we replying to. */
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
if($autoResponse === true){
mail($email, $autoResponseSubject, $autoResponseMessage, $autoResponseHeaders);
}
echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
<?php
$autoResponse = true; //if set to true auto response email will be sent, if you don't want autoresponse set it to false
$autoResponseSubject = "Demo Contact Form";
$autoResponseMessage = "Hi, thank you testing the JQuery Contact Form Demo.";
$autoResponseHeaders = "From: email_from@yourWebsite.com";
//we need to get our variables first
$email_to = 'some@mail.com'; //the address to which the email will be sent
$topic = $_POST['topic'];
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['message'];
$message = "From: $name \r\nEmail: $email \r\nTopic: $topic \r\nMessage: \r\n$msg";
/*the $header variable is for the additional headers in the mail function,
we are asigning 2 values, first one is FROM and the second one is REPLY-TO.
That way when we want to reply the email gmail(or yahoo or hotmail...) will know
who are we replying to. */
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
if(mail($email_to, $subject, $message, $headers)){
if($autoResponse === true){
mail($email, $autoResponseSubject, $autoResponseMessage, $autoResponseHeaders);
}
echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
if(mail($email_to, $subject, $message, $headers)){
if($autoResponse === true){
$success = mail($email, $autoResponseSubject, $autoResponseMessage, $autoResponseHeaders);
if ($success){
//update database
} else {
//throw error
}
}