5

I have tried so many different approaches, but cannot successfully send an EMail through SMTP in PHP using the mail() function.

 <?php
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer();
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'skchourasia@asselslutions.com';
$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('support@wordpressapi.com/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.";
 ?>

What am I doing wrong? I am getting the following error:

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"
user1811549
  • 59
  • 1
  • 3
  • 1
    Your error message is not complete, the line number is missing. Go to that line number, and tell us what is the code in the previous lines. The error is there. – Jocelyn Nov 09 '12 at 10:29
  • i have updated my code , the error is in line no 8 plz chk it now – user1811549 Nov 09 '12 at 10:34
  • Even though the code you posted is not perfect, I don't see any serious error that could lead to a parse error. Is it really the code of `content.php` you posted? – Jocelyn Nov 09 '12 at 14:10
  • You can have a reference [here](http://codex.wordpress.org/Function_Reference/wp_mail). You can send the mail using `wp_mail` function. – Rohit Pande Nov 09 '12 at 10:38

1 Answers1

1

This:

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

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

should be this:

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

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

Anyway, it seems you are trying to send an e-mail both via PHPMailer class and mail() native PHP function. You may be just testing but I am not really sure what are you trying to do.

jmic
  • 907
  • 2
  • 10
  • 22
  • after applying single quotes in your_message, same error as previous occurs – user1811549 Nov 09 '12 at 10:47
  • plz tell me how i can send mail using smtp either through PHPMailer class or mail() function – user1811549 Nov 09 '12 at 10:54
  • @digitalis You are right about the missing single quotes, but this is really not the cause of the parse error. A missing single quote around an array key causes a notice or warning, not an error. – Jocelyn Nov 09 '12 at 14:10