繁体   English   中英

我收到PhpMailer发送错误

[英]I am getting PhpMailer sending error

我正在尝试从我的网站联系表中使用phpmailer在Gmail中发送邮件。 并得到这个错误:

解析错误:语法错误,第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>

那么有人可以解决这个问题吗?

根据您的问题,如果您尝试通过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]已弃用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM