php
  • html
  • 2015-11-04 175 views 1 likes 
    1

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

    我的代码是

    HTML代码

    <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 = "[email protected]"; 
    $email_to = "[email protected]"; 
    
    $email_sub = "Enquiry from contact us form"; 
    
    $email_bod = 
    "$name 
    
    ". 
    
    $headers = "From:[email protected]"; 
    
    
    
    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实际使用

    服务器:Microsoft-IIS/7.5 有什么办法来纠正这个错误?

    谁能帮我

    +2

    你在行尾有两个点('.')。 '.'旨在连接字符串。 –

    +0

    你正在使用本地服务器(xampp,wampp等)或在线服务器 – deemi

    +0

    请查看http://php.net/manual/en/mail.configuration.php – Robert

    回答

    0

    你需要SMTP服务器或配置为发送邮件的邮件服务。

    +0

    有什么办法可以添加邮件服务 – Nisha

    +1

    你可以使用'邮件'功能没有SMTP – Justinas

    +0

    @Justinas你可以使用邮件功能,但邮件不会被发送。 –

    -1

    需要完成头

    $header = 'MIME-Version: 1.0' . "\r\n"; 
    $header.= 'From: NAME <[email protected]>' . "\r\n"; 
    $header.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    $header.= 'X-Priority: 3 \r\n'; 
    

    邮件功能只有在服务器上&工作在本地主机无法正常工作(它显示错误)

    +0

    是什么? :)关于邮件捕获器或定义应用程序中的SMTP服务器呢? – Robert

    0

    首先,你应该添加name到您的提交按钮这样

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

    而且当这设置您运行您的代码

    if(isset($_POST['submit_form'])) { 
        //Rest of your code 
    } 
    
    0

    我认为问题是,你有没有在代码

    0

    “80端口已被使用”关闭了,如果情况通常意味着其他程序正在使用此端口。

    首先更改您的httpd.conf文件(在Apache文件夹下)。 找到“ServerName”并用“:8080”更改默认端口“80”。 然后使用“localhost/8080”而不是“localhost”在您的浏览器上访问本地主机。

    然后,为了能够在本地发送电子邮件,您需要配置您的服务器。 最简单的方法是安装一个软件,如假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:找到“sendmail_path”并将路径添加到sendmail.exe。

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

    相关问题