如何使用基本的PHP发送电子邮件?

时间:2016-01-12 11:07:12

标签: php

enquiry.php

     <form  id="style_contact" method="POST" name="contactForm" action="sendmail.php" enctype="multipart/form-data">
                        <table width="100%" border="0" align="left">
                          <tr>
                            <td>Name<span style="color:#96070d; padding:5px;">*</span></td>
                            <td><input name="fname" type="text" placeholder="" class="feiald" /></td>
                          </tr>
                          <tr>
                            <td>Telephone<span style="color:#96070d; padding:5px;">*</span></td>
                            <td><input name="phone" type="text" placeholder="" class="feiald" value="" /></td>
                          </tr>
                          <tr>
                            <td>Mobile No<span style="color:#96070d; padding:5px;">*</span></td>
                            <td><input name="mobile" type="text" placeholder="" class="feiald" value="" /></td>
                          </tr>
                          <tr>
                            <td>Email<span style="color:#96070d; padding:5px;">*</span></td>
                            <td><input name="email" type="text" placeholder="" class="feiald" value="" /></td>
                          </tr>
                          <tr>
                            <td>Subject<span style="color:#96070d; padding:5px;">*</span></td>
                            <td><input name="subject" type="text" placeholder="" class="feiald" value="" /></td>
                          </tr>
                          <tr>
                            <td>Message<span style="color:#96070d; padding:5px;">*</span></td>
                            <td><textarea name="message" cols="36" rows="3" class="feiald" placeholder=""></textarea></td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                             <td><input class="button" type="submit" value="Submit" /></td>
                          </tr>
                        </table>
        </form>

sendmail.php

               <?php


    $name = $_POST['fname'];
    $telephone = $_POST['phone'];
    $mobile = $_POST['mobile'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $msg = $_POST['message'];

    $to = 'cd4xltech@gmail.com';

    $message = 'Name : '.$name.'Telephone : '.$telephone.'Mobile No : '.$mobile.'Email : '.$email.'Message : '.$msg;

    mail($to,$subject,$message);


    header('location: enquiry.php?msg="Your message has been sent successfully!!"');

&GT;

我已经编写了将电子邮件发送到基本php中的email-id的代码。我已经上传到服务器上了。但它没有用。任何人都可以告诉这段代码中的错误是什么?正在显示消息“您的消息已成功发送”。但邮件不在收件箱中。

2 个答案:

答案 0 :(得分:0)

如果您通过Php要求简单的电子邮件。然后你可以使用Php mail()方法。然后你需要避免电子邮件发送垃圾邮件

答案 1 :(得分:0)

尝试这个...非常简单,它肯定会帮助你

     <?php 
   $to = "xxxxx@gmail.com";
   $subject = "This is Test Mail";
   $message = "<b>This is HTML message.</b>";
   $message .= "<h1>This is headline.</h1>";
   $header = "From:yyyyyy@gmail.com\r\n";
   $header .= "Cc:xxx@gmail.com \r\n";
   $header .= "MIME-Version: 1.0\r\n";
   $header .= "Content-type: text/html\r\n";
   $retval = mail ($to,$subject,$message,$header);
?>