不接受电子邮件形式 [英] not receiving form emails
问题描述
我试过前面无解,所以我将我所有的code,试图解决这个问题。我没有收到这种形式在我的收件箱,但我的AJAX功能工作像它应该。我GoDaddy的托管,并正在对wampp的Mac运行在本地。我试着无济于事多个不同的电子邮件地址。我不想使用PHP邮件。我只是想这样的功能,而不是什么,似乎在做它拍摄到的电子邮件空间outter
正确HTML
< DIV CLASS =块>
< DIV CLASS =做>
< H1>谢谢!我收到了你的信息< / H1>
< / DIV>
< DIV CLASS =形与GT;
<形式方法=邮报行动=脚本/ process.php>
<输入名称=名称级=文本占位符=名称类型=文本/>
<输入名称=电子邮件级=文本占位符=电子邮件类型=文本/>
< textarea的名字=意见级=文本textarea的占位符=注释>< / textarea的>
<输入名称=提交值=走吧! ID =提交类型=提交/>
< DIV CLASS =加载>< / DIV>
< /形式GT;< / DIV>
< / DIV>
< DIV CLASS =清除>< / DIV>
< / DIV>
< / DIV>
jQuery验证和Ajax
$('#提交)。点击(函数(){
//从所有字段的数据
变种名称= $('输入[名称=名称]);
变种的电子邮件= $('输入[名称=电子邮件]');
VAR评论= $('textarea的[名称=评论]');
VAR emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
变种emailVal = email.val();
//简单的验证,以确保用户输入的东西
//如果发现错误,hightlight类添加到文本字段
如果(!emailReg.test(emailVal)){
email.addClass('hightlight');
返回false;
}否则email.removeClass('hightlight');
如果(name.val()==''){
name.addClass('hightlight');
}其他{name.removeClass('hightlight');}
如果(email.val()==''){
email.addClass('hightlight');
}其他{email.removeClass('hightlight');}
如果(comment.val()==''){
comment.addClass('hightlight');
}其他{email.removeClass('hightlight');}
如果(name.val()==''|| email.val()==''|| comment.val()==''){
返回false;
}
//组织数据正确
VAR数据=NAME ='+ name.val()+'&放大器;电子邮件='+ email.val()+'&放大器;网站='
+ website.val()+'&放大器;注释='+ EN codeURIComponent(comment.val());
//禁用所有的文本字段
$('文字')ATTR(禁用,真)。
//显示加载标志
$('。装)显示()。
//启动了ajax
$阿贾克斯({
//这是处理数据和发送邮件的PHP文件
网址:脚本/ process.php
// GET方法
键入:GET,
//传递数据
数据:数据,
//不要缓存页面
缓存:假的,
//成功
成功:函数(HTML){
//如果process.php返回1 /真(发送邮件成功)
如果(HTML代码== 1){
//隐藏窗体
$('表')淡出(慢)。
//显示成功消息
$(完成。)淡入(慢)。
//如果process.php返回0 / FALSE(发送邮件失败)
}其他警报('对不起,意外错误,请稍后再试。);
}
});
//取消提交按钮的默认行为
返回false;
});
和我很遗憾地说PHP的我还不是很了解,现在
< PHP
//获得表单数据。
//获取 - 用户提交使用AJAX数据
// POST - 如果用户不支持javascript,我们将使用POST
$名字=($ _ GET ['名称'])? $ _GET ['名称']:$ _ POST ['名称'];
$电子邮件=($ _ GET [电子邮件])$ _ GET [电子邮件]:$ _ POST [电子邮件];
$评论=($ _ GET ['评论'])$ _ GET ['评论']:$ _ POST ['评论'];
//标志,表示其使用的方法。如果POST将其设置为1
如果($ _ POST)$后= 1;
//简单的服务器端验证POST数据,当然,
//您应该验证电子邮件
如果(!$名)$错误[计数($错误)] ='请输入您的名字。;
如果(!$电子邮件)$错误[计数($错误)] ='请输入你的电子邮件。;
如果(!$评论)$错误[计数($错误)] ='请输入您的评论。;
//如果错误数组为空,发送邮件
如果(!$错误){
//收件人 - 这改变您的姓名和电子邮件
$到='myemail@gmail.com';
//发件人
从$ = $名。 '< 。 $电子邮件。 '>';
//主题和HTML邮件
$主题='的评论。 $名称;
$消息='
!< DOCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< HTML的xmlns =http://www.w3.org/1999/xhtml>
< HEAD>< /头>
<身体GT;
<表>
< TR>< TD>名称< / TD>< TD> 。 $名字。 '< / TD>< / TR>
< TR>< TD>电子邮件< / TD>< TD> 。 $电子邮件。 '< / TD>< / TR>
< TR>< TD>注释< / TD>< TD> 。 nl2br($评论)。 '< / TD>< / TR>
< /表>
< /身体GT;
< / HTML>';
//发送邮件
$结果=的sendmail($到,$主题,$消息,从$);
//如果POST使用,显示消息马上
如果($ _ POST){
如果($结果)回声谢谢你!马特已经收到您的信息。
其他回声对不起,意外错误。请稍后再试';
//否则如果使用GET,返回布尔值,使得
// AJAX脚本可以做出相应的反应
// 1表示成功,0表示失败
} 其他 {
回声$结果;
}
//如果错误数组有值
} 其他 {
//显示错误消息
为($ i = 0; $ I<计数($错误); $ I ++)回声$错误[$ i]。 '< BR />';
回声'< A HREF =form.php的>返回< / A>';
出口;
}
//简单的电子邮件功能与HTML标题
功能的sendmail($到,$主题,$消息,从$){
$标题=MIME-版本:1.0。 \ r \ N的;
$标题=内容类型:text / html的;字符集= ISO-8859-1。 \ r \ N的;
$标题=发件人:。 $而来。 \ r \ N的;
$结果=电子邮件($到,$主题,$消息,$头);
如果($结果)返回1;
否则返回0;
}
?>
有关于派遣PHP邮件到不同的邮件服务器,因此许多问题。例如,当我想发送电子邮件到Gmail的主机我从来不包括 \ r
新线,我只用去\ñ
。也许你的问题是与你的头,我把我的code这里,看看你能得到什么:
函数发送($地址,$主题,$内容,$从='',$的HTML = FALSE,$编码=UTF-8)
{
如果(空($地址)||空($内容))返回;
$标题=;
如果($来自!='')
{
$标题=来源:{$从} \ N。
$标题=回复:{$从} \ N。
}
$标题=为:{$地址} \ N。
如果($ HTML)
{
$标题=MIME-版本:1.0 \ N。
$标题=内容类型:text / html的;字符集= {$编码} \ N。
$标题=内容传输编码:8位\ N。
}
。$标题=X-优先级:1(最高)\ N的;
$标题=X-MSMAIL优先级:高\ N。
$标题=重要性:高\ N。
$标题=X梅勒:PHP /。 phpversion();
或者set_time_limit(30);
电子邮件($地址,$主题,$内容,$头);
}
发送('myemail@myhost.com','标题','内容','myemail< myemail@myhost.com>,FALSE);
I tried earlier with no solution, so I'm adding all my code to try and resolve this issue. I am not getting this form in my inbox, but my ajax function is working like it should. I have godaddy hosting, and am running it locally on wampp for mac. I've tried multiple different email addresses with no avail. I don't want to use php mailer. I just want this to function properly instead of what it seems to be doing which is shooting emails into outter space
html
<div class="block">
<div class="done">
<h1>Thank you! I have received your message.</h1>
</div>
<div class="form">
<form method="post" action="scripts/process.php">
<input name="name" class="text" placeholder="Name" type="text" />
<input name="email" class="text" placeholder="Email" type="text" />
<textarea name="comment" class="text textarea" placeholder="Comment"></textarea>
<input name="submit" value="Let's Go!" id="submit" type="submit" />
<div class="loading"></div>
</form></div>
</div>
<div class="clear"></div>
</div>
</div>
jquery validation and ajax
$('#submit').click(function () {
//Get the data from all the fields
var name = $('input[name=name]');
var email = $('input[name=email]');
var comment = $('textarea[name=comment]');
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var emailVal = email.val();
//Simple validation to make sure user entered something
//If error found, add hightlight class to the text field
if (!emailReg.test(emailVal)){
email.addClass('hightlight');
return false;
} else email.removeClass('hightlight');
if (name.val()=='') {
name.addClass('hightlight');
}else{name.removeClass('hightlight');}
if (email.val()=='') {
email.addClass('hightlight');
}else{email.removeClass('hightlight');}
if (comment.val()=='') {
comment.addClass('hightlight');
}else{email.removeClass('hightlight');}
if (name.val()=='' || email.val()=='' || comment.val()=='') {
return false;
}
//organize the data properly
var data = 'name=' + name.val() + '&email=' + email.val() + '&website='
+ website.val() + '&comment=' + encodeURIComponent(comment.val());
//disabled all the text fields
$('.text').attr('disabled','true');
//show the loading sign
$('.loading').show();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "scripts/process.php",
//GET method is used
type: "GET",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function (html) {
//if process.php returned 1/true (send mail success)
if (html==1) {
//hide the form
$('.form').fadeOut('slow');
//show the success message
$('.done').fadeIn('slow');
//if process.php returned 0/false (send mail failed)
} else alert('Sorry, unexpected error. Please try again later.');
}
});
//cancel the submit button default behaviours
return false;
});
and the php which I regret to say I know very little about for now
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course,
//you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$comment) $errors[count($errors)] = 'Please enter your comment.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - change this to your name and email
$to = 'myemail@gmail.com';
//sender
$from = $name . ' <' . $email . '>';
//subject and the html message
$subject = 'Comment from ' . $name;
$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
</table>
</body>
</html>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! Matt has received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo '<a href="form.php">Back</a>';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
There are so many issues on sending PHP mails to different mail servers. For example, when I want to send email to GMail hosts I never include \r
for new lines and I only go with \n
. Maybe your problem is with your headers, I place my code here and see what you can get:
function send($address, $subject, $content, $from = '', $html = FALSE, $encoding = 'utf-8')
{
if(empty($address) || empty($content)) return;
$headers = "";
if($from != '')
{
$headers .= "From: {$from}\n";
$headers .= "Reply-To: {$from}\n";
}
$headers .= "To: {$address}\n";
if($html)
{
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset={$encoding}\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
}
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$headers .= "X-Mailer: PHP/" . phpversion();
set_time_limit(30);
mail($address, $subject, $content, $headers);
}
send('myemail@myhost.com', 'title', 'content', 'myemail <myemail@myhost.com>', FALSE);
这篇关于不接受电子邮件形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!