1

好的...所以我从几个不同的网站和前任的组合中获取了这个 PHP 联系表。我已经与它搏斗了几个小时,但无法弄清楚。

平心而论,知道 PHP 根本不是我的强项,(我是一名客户端程序员)。这是下面的代码,如果可以,请帮助。谢谢!

以下是我看到的一些错误消息:

最新:*解析错误:语法错误,第 11 行 /home/[...] 中的意外 T_IF*

之前,这是错误消息,但我相信我修复了“空白字段”部分:

您似乎留下了一个空白字段。

请务必填写您的全名、电子邮件地址、主题和详细信息。单击返回箭头返回到联系表。

来自:...列表:;收件人地址的语法非法

回复:...列表:;收件人地址的语法非法

X-Mailer:...列表:;收件人地址的语法非法

感谢您,[姓名],与我们联系!

这是HTML

<form action="contactus.php" method="post" class="create">
     <fieldset>
    <legend align="center">Please fill out details below and click "Submit"</legend>
    <div>
     <label for="fullname" class="fixedwidth">Full Name</label>
     <input type="text" name="fullname" id="fullname" class="input2"/>
    </div><br/>
    <div>
     <label for="email" class="fixedwidth">Email</label>
     <input type="text" name="email" id="email" class="input2"/>
    </div><br/>
      <div>
     <label for="subject" class="fixedwidth">Subject</label>
     <input type="text" name="subject" id="subject" class="input2"/>
    </div><br/>
    <div>
    <label for="details" class="fixedwidth">Body</label>
     <textarea id="details" name="details" cols="62" rows="20"></textarea>
    </div>
    <div class="buttonarea">
        <input type="submit" name="submit" id="submit" value="Submit"/>
    </div>

    </fieldset>
   </form>

...这是contactus.php 文件:

<?php

 $fullname = $_POST['fullname'];
 $subject = $_POST['subject'];
 $details = $_POST['details'];
 $email = $_POST['email'];

//*** Function to check email address */
 function checkemail($email) { 
  $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)@[a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z]{2,3})$/'
   if (eregi($regex ,$email))
   { 
    return true; 
   } 
    else
   { 
    return false; 
   } 
 }

//*** Check to see if the email address is valid */
 else if (checkemail($email) == false) { 
  echo "<br/><br/><p><center>It appears that you have entered an invalid email address.<br/> Please check your email again.</p>";
 }

//*** Mail Processing */
 if ($_POST['submit']) {
 //Check for blank fields
  if ($fullname !== "" && $email !== "" && $subject !== "" && $details !== "") {
   echo "<br/><br/><p><center>It appears that you left a blank field.<br/> 
   Please make sure you fill in your full name, email address, subject, and details.<br/>
   Click the back arrow to return to the contact form.</p>";
  }

//*** Send Mail**/
 $to = 'sgraffito22@gmail.com';
 $fullname = $_POST['fullname'];
 $subject = $_POST['subject'];
 $details = $_POST['details'];

 $headers = 'From: '.$email."\r\n".
 'Reply-To: '.$email."\r\n" .
 'X-Mailer: PHP/' . phpversion();

 mail($to, $fullname, $subject, $details, $headers);
 echo "<br><br><p><center>Thank you, $fullname, for contacting us!</p><br><br>";

}

?> 
4

2 回答 2

0

;在末尾缺少 a

$regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)@[a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z]{2,3})$/'

您的From, Reply-to, 和X-Mailer语法错误可能是由在'"in之间切换引起的$headers

$headers = 'From: '.$email."\r\n".
  'Reply-To: '.$email."\r\n" .
   'X-Mailer: PHP/' . phpversion(); 

尝试更改为 -

$headers  = "From: ".$email."\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
于 2012-08-29T03:03:54.313 回答
0

由于 Sean 给出了正则表达式解决方案,

这是我以前使用的项目正则表达式,

$regex= "/^[\.a-z0-9_\-]+[@][a-z0-9_\-]+([.][a-z0-9_\-]+)+[a-z]{1,4}$/i";

这是 PHP 邮件的另一种替代方案,您需要下载 phpmailer 插件才能使此邮件正常工作。

<?php
// mail config start 

$emailAddress = 'youremailhere';
$replyAdress ='yourreceipientemailhere';
$replyName = 'yourreceipientname';
$msgSubject= 'yoursubjecthere';


// mail config end 

// Include the class,
require "phpmailer/class.phpmailer.php";

//Type your message here:
$msg = 'blablayourmessagehere';

//The mailing process begins!!
$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($replyAdress, $replyName);
$mail->AddAddress($emailAddress);
$mail->SetFrom($replyAdress, $replyName);
$mail->Subject = "New: ".$replyName." have sent a ".$msgSubject." message";

$mail->MsgHTML($msg);

$mail->Send();

?>
于 2012-08-29T06:32:41.207 回答