parsing - PHPMailer error - HTML email error -


i new php , installed phpmailer using composer in system. facing problem html message trying send.

i have tried send plain text , working fine , getting response of phpmailer.

below code :

    <?php      require_once 'autoload.php';      $mail = new phpmailer;      $mail->issmtp();     $mail->host = 'smtp.gmail.com';     $mail->smtpauth = true;     $mail->username = 'email@exapmle.com';     $mail->password = 'password';     $mail->smtpsecure = 'ssl';     $mail->port = 465;      $mail->from="mailer@example.com";     $mail->fromname="my site's mailer";     $mail->sender="mailer@example.com";     $mail->addreplyto("replies@example.com", "replies site");      $mail->addaddress("receiver@example.com");     $mail->subject = "test 1";      $mail->ishtml(true);      $mail->body = '<html>     <head>     <link href="http://alikan.esy.es/untitled1.css" rel="stylesheet">     <link href="http://alikan.esy.es/index.css" rel="stylesheet">     <script src="http://alikan.esy.es/jquery-1.11.1.min.js"></script>     <script src="http://alikan.esy.es/fancybox/jquery.easing-1.3.pack.js"></script>     <link rel="stylesheet" href="http://alikan.esy.es/fancybox/jquery.fancybox-1.3.0.css">     <script src="http://alikan.esy.es/fancybox/jquery.fancybox-1.3.0.pack.js"></script>     <script src="http://alikan.esy.es/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>     <script src="http://alikan.esy.es/wwb10.min.js"></script>     </head>     <body>     <div id="wb_text1" style="position:absolute;left:223px;top:70px;width:250px;height:16px;z-index:0;text-align:left;">     <span style="color:#000000;font-family:arial;font-size:13px;"><a href="javascript:displaylightbox('http://www.google.com/index.php',{width:1000,height:1000})" target="_self">this email body</a></span></div></body></html>';     $mail->altbody="this text alternative body.";      if(!$mail->send())     {        echo "error sending: " . $mail->errorinfo;;     }     else     {        echo "letter sent";     }     ?> 

and error code after trying send :

    ( ! ) parse error: syntax error, unexpected 'http' (t_string) in c:\wamp\www\vendor\index.php on line 37 

you opened body string single quote ':

$mail->body = '<html>... 

and use again in html string declare parameter:

...javascript:displaylightbox('http://www.google.com/index.php',... 

if string delimited single or double quotes, if contains same character must escaped, otherwise php parser think string ends @ next occurrence of opening quote. if delimit single quotes using double ones in content without escaping ok, , vice versa.

fix escaping 2 ' way:

...javascript:displaylightbox(\'http://www.google.com/index.php\',... 

edit:

furthermore, if sending html body, remember set ishtml flag before sending mail:

$mail->ishtml(true); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -