2012-11-09 51 views
5

Tôi đã thử rất nhiều cách tiếp cận khác nhau, nhưng không thể gửi thành công một EMail qua SMTP bằng PHP sử dụng hàm mail().Gửi một EMail bằng cách sử dụng Wordpress

<?php 
require_once ABSPATH . WPINC . '/class-phpmailer.php'; 
require_once ABSPATH . WPINC . '/class-smtp.php'; 
$phpmailer = new PHPMailer(); 
$phpmailer->SMTPAuth = true; 
$phpmailer->Username = '[email protected]'; 
$phpmailer->Password = 'password01'; 
  
$phpmailer->IsSMTP(); // telling the class to use SMTP 
$phpmailer->Host       = "mail.asselsolutions.com"; // SMTP server 
$phpmailer->FromName   = $_POST[your_email]; 
$phpmailer->Subject    = $_POST[your_subject]; 
$phpmailer->Body       = $_POST[your_message];                      //HTML Body 
$phpmailer->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
$phpmailer->WordWrap   = 50; // set word wrap 
$phpmailer->MsgHTML($_POST[your_message]); 
$phpmailer->AddAddress('[email protected]/files/', 'Wordpress support'); 
//$phpmailer->AddAttachment("images/phpmailer.gif");             // attachment 
if(!$phpmailer->Send()) { 
 echo "Mailer Error: " . $phpmailer->ErrorInfo; 
} else { 
 echo "Message sent!"; 
} 
$to = $_REQUEST['to']; 
$subject = $_REQUEST['subject']; 
$message = $_REQUEST['message']; 
$from = $_REQUEST['from']; 
$headers = "From:" . $from; 

$mail = mail($to,$subject,$message,$headers); 

echo "Mail Sent."; 
?> 

Tôi đang làm gì sai? Tôi nhận được lỗi sau:

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\wp-vtr\wp-content\themes\twentyeleven\content.php on line 8

$phpmailer->IsSMTP(); // telling the class to use SMTP" 
+1

Thông báo lỗi của bạn chưa hoàn thành, số dòng bị thiếu. Chuyển đến số dòng đó và cho chúng tôi biết mã trong các dòng trước đó là gì. Lỗi là có. – Jocelyn

+0

tôi đã cập nhật mã của mình, lỗi này nằm trong dòng số 8 plz chk bây giờ là – user1811549

+0

Mặc dù mã bạn đăng không hoàn hảo, tôi không thấy bất kỳ lỗi nghiêm trọng nào có thể dẫn đến lỗi phân tích cú pháp. Nó thực sự là mã của 'content.php' bạn đã đăng? – Jocelyn

Trả lời

1

này:

$phpmailer->FromName = $_POST[your_email]; 
$phpmailer->Subject = $_POST[your_subject]; 
$phpmailer->Body  = $_POST[your_message]; 

$phpmailer->MsgHTML($_POST[your_message]); 

phải được điều này:

$phpmailer->FromName = $_POST['your_email']; 
$phpmailer->Subject = $_POST['your_subject']; 
$phpmailer->Body  = $_POST['your_message']; 

$phpmailer->MsgHTML($_POST['your_message']); 

Dù sao, có vẻ như bạn đang cố gắng gửi một e-mail cả hai thông qua lớp PHPMailer và mail() hàm PHP gốc. Bạn có thể chỉ là thử nghiệm nhưng tôi không thực sự chắc chắn bạn đang cố gắng làm gì.

+0

sau khi áp dụng dấu nháy đơn trong your_message, lỗi giống như trước xảy ra – user1811549

+0

plz cho tôi biết cách tôi có thể gửi thư bằng cách sử dụng smtp thông qua hàm PHPMailer hoặc thư() – user1811549

+0

@digitalis Bạn nói đúng về dấu trích dẫn bị thiếu, nhưng điều này thực sự không nguyên nhân của lỗi phân tích cú pháp. Một trích dẫn đơn mất tích xung quanh một khóa mảng gây ra một thông báo hoặc cảnh báo, không phải là lỗi. – Jocelyn

Các vấn đề liên quan