电子邮件不是用PHP发送的

时间:2015-11-04 10:58:19

标签: php html

我正在用HTML创建单页面应用程序。我是PHP新手。在那我有一个留下评论页面。我有文本框输入名称和电子邮件。点击按钮邮件时我有按钮将发送给用户。我正在用PHP编写电子邮件代码。

我的代码是

HTML CODE

<div class="coment-form">
                        <h4>LEAVE YOUR COMMENT</h4>
                        <form  class="form" id='form' name='form' method="post" action="service.php">
                            <input type="text" name="name" value="Name :" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name :';}" required="">
                            <input type="email" name="email" value="Email (will not be published)* :" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email (will not be published)* :';}" required="">
                            <input type="text" name="cmt" value="Website :" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Website :';}" required="">
                            <textarea type="text" name="message" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Your Comment...';}" required="">Your Comment...</textarea>
                            <input type="submit" value="Submit Comment" >
                        </form>
                    </div>  

PHP代码:

service.php文件

<?php
include('config.php');
$name=$_POST['name'];

$email=$_POST['email'];

$cmt = $_POST['cmt'];
$message=$_POST['message'];


if ($_SERVER["REQUEST_METHOD"] == "POST") {


//mail code
 $to = $_POST['email'];

$email_subject = "Dear $name";

$email_body = "Thank you for inquiring about our Services advertised on our webSite.
Each of the listed services we offer are uniquely different. 

One of our representatives will contact you soon, would help and appreciate if you can drop a line with a suitable 
Date and Time for a Phone / Skype discussion.

Once again, thank you for your interest in our services.

Cordially,

 ".






//mail code
// $email_to = "venkatj@acute.company";
 $email_to = "sbshnr@gmail.com";

$email_sub = "Enquiry from contact us form";

$email_bod = 
 "$name

 ".

 $headers = "From:nisha@acute.company";



mail($to,$email_subject,$email_body,$headers);
mail($email_to,$email_sub,$email_bod,$headers);


echo '<script type="text/javascript">alert("Thank you admin will contact you soon...!");window.location.assign("Contact_us.html");</script>';

//header('Location: contact.php');





?>

我的问题是点击按钮时电子邮件未发送。

我在我的机器中安装了WaMp。它是橙色,同时检查我得到一个错误

您的端口80实际上由

使用

服务器:IIS / 7.5 有没有办法纠正这个错误?

任何人都可以帮助我

5 个答案:

答案 0 :(得分:0)

您需要配置SMTP邮件服务或邮件服务以发送邮件。

答案 1 :(得分:0)

首先,您应该像这样将<{1}}添加到提交按钮

name

如果设置了此项,则运行代码

 <input type="submit" name="submit_form" value="Submit Comment" >

答案 2 :(得分:0)

我认为问题在于你还没有关闭代码中的if条件

答案 3 :(得分:0)

&#34;已使用端口80&#34;通常意味着其他程序正在使用此端口。

首先更改您的httpd.conf文件(在Apache文件夹下)。 查找&#34; ServerName&#34;并更改默认端口&#34;:80&#34;通过&#34;:8080&#34;。 然后使用&#34; localhost / 8080&#34;访问浏览器上的localhost。而不是&#34; localhost&#34;。

然后,为了能够在本地发送电子邮件,您需要配置您的服务器。 最简单的方法是安装像Fake Sendmail(http://glob.com.au/sendmail/)这样的软件并按照说明操作。

配置非常简单,特别是如果发件人电子邮件是gmail(通过您的信息替换星号):

[sendmail] 
smtp_server=smtp.gmail.com 
smtp_port=587 
default_domain=gmail.com 
error_logfile=error.log 
auth_username=********@gmail.com 
auth_password=****** 
pop3_server= 
pop3_username= 
pop3_password= 
force_sender=****@gmail.com 
force_recipient= 
hostname=

你最终必须更新你的php.ini:find&#34; sendmail_path&#34;行并添加sendmail.exe的路径。

重新启动WAMP,它应该可以工作:)

答案 4 :(得分:-1)

您需要填写标题

$header = 'MIME-Version: 1.0' . "\r\n";
$header.= 'From: NAME <info@domain.com>' . "\r\n";
$header.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header.= 'X-Priority: 3 \r\n';

邮件功能仅适用于服务器&amp;不能在本地主机上工作(它显示错误)