-2

from を作成し、多くの php コードを試しましたが、2 日以来、これに本当にうんざりしています。送信されたデータを電子メールに送信できません。誰か助けてください。 php ですがw3schools(php mail)のコードから色々試してみました

ここに私が作成した私のフォームがあります:

<form method="post" action="mail.php">
            <table border="0">
            <tr><td width="15" class="text"><img src="images/speechbubble.png" width="19" height="20">&nbsp;&nbsp;Feedback <br /> </td></tr>
            <tr><td class="text">Name</td></tr>
             <tr><td>
            <input type="text" name="Name" required="required" /></td></tr>
            <tr><td class="text">Email</td></tr>
            <tr><td><input type="email" name="Email"  required="required" /></td></tr>
            <tr><td class="text">Phone</td></tr>
           <tr><td><input type="tel" name="phone"  pattern="[0-9]{11}|[0-9]{10}" required></td></tr>
           <tr><td class="text">Message</td></tr>
            <tr><td><textarea name="Comments" rows="5" cols="20" required></textarea></td></tr>

           <tr><td style="text-align:right"> <input type="Submit" value="Submit"/></td></tr>
            </table>
            </form>

PHP :

<?php 
 $to = "info@appsysinfotech.com"; 
 $subject = "Contact Us"; 
 $email = $_REQUEST['email'] ; 
 $phone = $_REQUEST['phone'] ; 
 $headers = "From: $email"; 
 $sent = mail($to, $subject, $email, $phone, $headers) ; 
 if($sent) 
 {print "Your mail was sent successfully"; }
 else 
 {print "We encountered an error sending your mail"; }
 ?> 
4

1 に答える 1

0

mail.php では、次のように記述する必要があります。

<php
   $name = $_POST['Name'];
   $email = $_POST['Email'];
   $phone = $_POST['phone'];
   $comments = $_POST['Comments'];

   if(isset($name, $email, $phone, $comments)) { //check if all fields are set
       $message = 'Someone wrote a comment \n'; //
       $message .= 'Name: '.$name.'\n';         // 
       $message .= 'Email: '.$email.'\n';       // Build up the email message
       $message .= 'Phone: '.$phone.'\n';       //
       $message .= 'Comment: '.$comments.'\n';  //

       if(preg_match('/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/',$email)) { //check if the email address is well written
           if(mail('your@email.com', 'Set A Subject', $message)) { //send the email and check if it worked
               echo 'email sent succesfully';
           }
           else { //if it did not work print an error msg
               echo 'an error occurred, please try again later';
       }
       else { //if the email address is invalid print an error msg
           echo 'your email address seems to be invalid';
   }
   else { //if all input fields were not filled print an error msg
       echo 'please fill the whole form';
   }
?>
于 2013-09-18T18:04:18.477 に答える