简体   繁体   English

我收到PhpMailer发送错误

[英]I am getting PhpMailer sending error

I am trying to send mail in Gmail using phpmailer from my websites contact form. 我正在尝试从我的网站联系表中使用phpmailer在Gmail中发送邮件。 And getting this error : 并得到这个错误:

Parse error: syntax error, unexpected '@' in /home/dindaelectronics/public_html/mailer.php on line 19 解析错误:语法错误,第19行在/home/dindaelectronics/public_html/mailer.php中出现意外的'@'

Here is the PHP code, in which in line 19 has the error (which I am unable to understand). 这是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

}

?>

and Here is the HTML form... 这是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>

So can anybody solve this? 那么有人可以解决这个问题吗?

From your question, if you are trying to send through GMail then you should be configuring using GMail's SMTP parameters but if using your webmail then it should be your host's SMTP parameters . 根据您的问题,如果您尝试通过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";

Another thing is, [eregi_replace][1] is deprecated. 另一件事是, [eregi_replace][1]已弃用。

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

相关问题 为什么我在 PHPMailer 的代码中出现错误? - Why am I getting an error in the code from PHPMailer? 为什么我在Phpmailer中收到邮件延迟? - Why i am getting mail delayed in Phpmailer? phpmailer我没有任何附件,但是我收到邮件 - Phpmailer I am not getting any attachment, but i am receiving mail 当我尝试使用 phpmailer 发送邮件时,出现错误 - When i tried to send mail using phpmailer, i am getting error PHPMailer不发送电子邮件-我缺少简单的东西吗? - PHPMailer Not Sending Emails - Am I missing something simple? 为什么我在尝试使用phpmailer发送电子邮件激活新用户帐户时收到此错误 - Why am i getting this error when trying to send email for activation of new user account with phpmailer phpmailer 在本地主机上工作,但是当我将它上传到我的 ubuntu 服务器时,它给了我错误并且邮件没有发送(我使用的是 gmail smtp) - phpmailer working on localhost but when i upload it on my ubuntu server it gives me error and mail is not sending(I am using gmail smtp) PHPMAILER 不发送也不报错 - PHPMAILER Not sending and not giving error 使用PHP使用PHPmailer发送邮件时遇到身份验证错误 - Getting authentication error while sending mail with PHPmailer using PHP 使用 PHPMailer 从 ionic 发送 email 时出现错误响应 - Getting error response while sending email from ionic using PHPMailer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM