如何创建直接向Gmail发送电子邮件的表单?

时间:2014-06-24 08:24:08

标签: php html forms email gmail

我是一名前端设计师,所以我的PHP技能非常基础。对于我的个人作品集,我想制作一个联系表单,直接向我的Gmail地址发送消息。我无法实现这一目标。这是我的代码:

<?php
    error_reporting(0);
    $action=$_REQUEST['action'];
    if ($action=="") {
?>
<form action="" method="POST" enctype="multipart/form-data">
<h2>Form</h2>
<input type="hidden" name="action" value="submit">
<input name="name" type="text" value="" placeholder="Name"/><br>
<input name="email" type="text" value="" placeholder="Email"/><br>
<textarea name="message" placeholder="Message"></textarea><br>
<input name="cv" checked="true"> Yes, I would like to receive ****'s resume.<br>
<input type="submit" value="Send"/>
</form>
<?php
    } else {
        $name=$_REQUEST['name'];
        $email=$_REQUEST['email'];
        $message=$_REQUEST['message'];
        $cv=$_REQUEST['cv'];
        if (($name=="")||($email=="")||($message=="")) {
            echo "All fields are required. Please return to the <a href=\"\">form</a>.";
        } else {
            $from="From: $name<$email>\r\nReturn-path: $email";
            $subject="New message sent from your form";
            $curriculum="";
            if(isset($_REQUEST['cv'])){
                $curriculum="(!) This person would like to receive my resume.";
            }
            $cmessage=$message . "\r\n\r\n" . $curriculum;
            mail("my-email@gmail.com", $subject, $cmessage, $from);
            echo "Message sent!";
        }
    }  
?>

每当我尝试自己填写表单时,我都没有收到电子邮件。什么似乎是问题?

0 个答案:

没有答案