我正在尝试使用phpmailer从我的网站联系表单中发送邮件。并收到此错误:
解析错误:语法错误,意外' @'在 第19行/home/dindaelectronics/public_html/mailer.php
这是PHP代码,其中第19行有错误(我无法理解)。
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$mail = new PHPMailer();
$body = file_get_contents('contact.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->Host = "mail.yourdomain.com";
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 26;
$mail->Username = "yourname@yourdomain"; <-- **Line 19 which is indicating error**
$mail->Password = "yourpassword";
$email_to = "debnil2014@gmail.com";
$email_subject = "Checking PHP Mailer";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['address']) ||
!isset($_POST['email']) ||
!isset($_POST['mobile']) ||
!isset($_POST['subject']) ||
!isset($_POST['query'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$last_name = $_POST['address']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['mobile']; // not required
$comments = $_POST['subject']; // required
$comments = $_POST['query']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Address: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Mobile: ".clean_string($telephone)."\n";
$email_message .= "Subject: ".clean_string($comments)."\n";
$email_message .= "Query: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<?php
}
?>
以下是HTML表单......
<form name="contactform" method="post" action="mailer.php">
<input type="text" name="name" placeholder="Your Name" required>
<textarea name="address" placeholder="Address" required></textarea>
<input name="email" type="text" placeholder="Email id" required>
<input name="mobile" type="text" placeholder="Mobile No." required>
<input name="subject" type="text" placeholder="Subject" required>
<textarea name="query" placeholder="Query" required></textarea>
<div class="clear"></div>
<input type="submit" name="submit" value="SUBMIT">
</form>
那么有人可以解决这个问题吗?
答案 0 :(得分:0)
根据您的问题,如果您尝试通过 GMail 发送,那么您应该使用 GMail的SMTP参数进行配置,但是如果使用 webmail 那么它应该是你的主机的SMTP参数。
$mail->Host = "mail.yourdomain.com";
$mail->SMTPDebug = 2; //Change this to "true" to also see your errors
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 26;
$mail->Username = "yourname@yourdomain"; <-- **Line 19 which is indicating error**
$mail->Password = "yourpassword";
另一件事是,[eregi_replace][1]
已被弃用。