使用$ _RESQUEST PHP表单发送电子邮件错误

时间:2015-11-02 16:18:59

标签: php forms email request

我有联系表格,我在第2行收到错误。

第2行看起来如下:

$action=$_REQUEST['action'];

错误消息是:

Notice: Undefined index: action in /Applications/XAMPP/xamppfiles/htdocs/mariefrance/indexMari.php on line 2

如何解决此错误?

PHP文件:



<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
    { 
    ?> 
    <form  action="" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" name="action" value="submit"> 
    Your name:<br> 
    <input name="name" type="text" value="" size="30"/><br> 
    Your email:<br> 
    <input name="email" type="text" value="" size="30"/><br> 
    Your message:<br> 
    <textarea name="message" rows="7" cols="30"></textarea><br> 
    <input type="submit" value="Send email"/> 
    </form> 
    <?php 
    }  
else                /* send the submitted data */ 
    { 
    $name=$_REQUEST['name']; 
    $email=$_REQUEST['email']; 
    $message=$_REQUEST['message']; 
    if (($name=="")||($email=="")||($message=="")) 
        { 
        echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
        } 
    else{         
        $from="From: $name<$email>\r\nReturn-path: $email"; 
        $subject="Message sent using your contact form"; 
        mail("chloele5@gmail.com", $subject, $message, $from); 
        echo "Email sent!"; 
        } 
    }   
?>
&#13;
&#13;
&#13;

0 个答案:

没有答案