【发布时间】:2014-10-20 12:02:57
【问题描述】:
最近,我购买了一个域名和主机。我还创建了一个包含联系表格的网页。我希望当用户在联系表单的 textarea 中写一些东西并点击 submit 然后该消息被发送到我的 gmail 帐户,这样我也可以回复这些消息。我也使用此脚本来执行此操作,但它不起作用。
这是 sendemail.php 文件
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'raunakhajela@gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
这是我在 index.php
中的联系表单代码<div class="contact" id="contact">
<div class="container-3x">
<div class="block-header"> <!-- Blocks Header -->
<h2 class="title">Contact Us</h2>
</div>
<div class="block-content"> <!-- Blocks Content -->
<form action="sendemailphp" method="post" class="trigger-form-animate">
<input type="text" value="" id="name" name="name" placeholder="Name *" />
<input type="text" value="" id="email" name="email" placeholder="Email *" />
<input type="text" value="" id="website" name="website" placeholder="Website *" />
<textarea type="text" value="" id="message" name="message" rows="3" placeholder="Your Message *" ></textarea>
<div class="clr"></div>
<button>Submit Message</button>
</form>
</div>
</div>
</div>
我也试过“http://www.mybloggertricks.com/2012/06/connect-your-website-email-address-to.html”这个教程,但它不起作用。无法在 gmail 添加另一个帐户窗口中找到“通过 Gmail 发送(更易于设置)”这个选项。
我该怎么做?请帮忙
【问题讨论】:
-
首先使用
@而不是checking for them 抑制错误对您的事业没有帮助。 -
是的,删除
@并同时使用error_reporting(E_ALL);和display_errors(1);还有var_dump($success);是真是假? -
伙计们,我对 php 了解不多,刚刚从 shapebootstrap.net/item/evento-free-music-event-template 下载了 eventto 模板,其中包含 sendemail.php 文件。我刚刚将电子邮件地址替换为我的电子邮件,在我创建的另一个模板上使用了这个文件并将文件上传到我的服务器上,但是当我尝试提交消息时,它只显示“成功”,但在我的 gmail 帐户上没有收到任何消息。
-
这个
action="sendemailphp"你确定不是action="sendemail.php"?在这样做时,它对我有用。已测试{"type":"success","message":"Thank you for contact us. As early as possible we will contact you "} -
sry 伙计们,这只是写这个问题时的语法错误,但是是的,我已经尝试过 action="sendemail.php"。然而它并没有成功......