Send email using PHP Mailer - php

I'm trying to send emails using PHP Mailer. The site is uploaded to a free hosting. The error is displayed about failed SMTP connection. I'm hoping to someone that has expertise in this matter.
Here goes my code.
require '../extensions/phpmailer/PHPMailerAutoload.php';
$emailAddress = 'SampleEmail';
$password = 'Emailpassword';
$subject = 'Invitation to employee portal';
$message = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Invitation</title>
<body style ="background:#eee;">
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable" style ="padding: 40px; max-width:640px;background-color:#f3f3f3;display:block;margin:0 auto; font-family:Lato, sans-serif; color:#626262;font-size:13px;line-height:22px;" width ="600">
<tbody>
<tr>
<td style ="background-color: #3552f2; padding: 34px 122px;">
<h1 width ="600" style ="max-width:600px;width:100%; text-align:center; color:#fff;">HRMS DHVTSU</h1>
</td>
</tr>
<tr>
<td style ="background-color: #ffffff; text-align: center; padding: 40px;">
<h1 style="font-size: 40px; color:#000; font-style: italic;">Sorry your account has been deactivated.</h1>
<br>
<p style ="color:#000; font-size: 16px;">For any questions please contact HR Department.</p>
<br>
<br>
</td>
</tr>
<tr>
<td style ="background-color: #3552f2; text-align: center; font-size: 16px; color: #fff;">
<p>© 2016. All rights reserved.</p>
</td>
</tr>
</tbody>
</table>
</body>';
$mail = new PHPMailer;
$mail->isSMTP();
// $mail->SMTPDebug = 2;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $emailAddress;
$mail->Password = $password;
$mail->setFrom('noreply#hrms.com', 'HRMS');
$mail->addReplyTo('johndoe#gmail.com', 'HRMS');
$mail->addAddress($email);
$mail->Subject = $subject;
$mail->msgHTML($message);
if (!$mail->send()) {
// $error = "Mailer Error: " . $mail->ErrorInfo;
// echo '<script>alert("'.$error.'");</script>';
return false;
}else {
$query = 'Update employee_has_credentials set status = '.self::STATUS_INACTIVE.' where id= '.$id.'';
$result = $this->con->prepare($query);
$result->execute(array($id));
if($result->rowCount()){
return true;
}else{
return false;
}
}

Possible duplicate of PHP Mailer issue use that code and it will fix your problem, because you have not added following code:
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php'
or go to above link more description you can see from that answer.

Related

PHPMailer doesn't send mail even after including SMTP.php

For some strange reason my PHP login system that sends a confirmation email to activate your account but it doesn't send anything.
<?php
$error = NULL;
require "phpmailer/class.phpmailer.php";
require "phpmailer/class.smtp.php";
require "phpmailer/PHPMailerAutoload.php";
if(isset($_POST['submit'])) {
//Form Data GET
$u = $_POST['u'];
$p = $_POST['p'];
$p2 = $_POST['p2'];
$e = $_POST['e'];
//Throw Username too short error
if(strlen($u) < 5){
$error = "(!) Your username must be at least 5 characters.";
}elseif($p2 != $p) {
//Throw password pair error.
$error .= "(!) Your passwords do not match :/";
}else{
//200 [OK]
//Establish Connection to Database
$mysqli = NEW MySQLi('localhost','root','','test');
//Convert special chars.
$u = $mysqli->real_escape_string($u);
$p = $mysqli->real_escape_string($p);
$p2 = $mysqli->real_escape_string($p2);
$e = $mysqli->real_escape_string($e);
//Generate Verification Key
$vkey = md5(time().$u);
//Insert account into database
$p = md5($p);
$insert = $mysqli->query("INSERT INTO accounts(username,password,email,vkey)
VALUES('$u','$p','$e','$vkey')");
if($insert){
//Start PHPMailer
$mail = new PHPMailer(true);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 0; //No Debug. Set to 3 for verbose logging.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; //Set to SSL to pass checks.
$mail->Host = "smtp.mail.com"; //Set to mail.com server, it has ssl, smtp, and it's free. If you'd like to use gmail, use smtp.gmail.com
$mail->Port = 465; //SSL/TLS Port for mail.com and gmail.com
//FILL WITH YOUR DETAILS
$mail->Username = 'example#mail.com';
$mail->Password = 'example';
//DON'T SET TO SENDER ADDRESS WILL FAIL SPF CHECKS!!!
$mail->SetFrom('example#mail.com', 'example');
$mail->AddAddress($e);
//Send the email.
$mail->Subject = trim("Email Verifcation");
$mail->isHTML(true);
//The Message
$mail->Body = '<h1>Hi, ' . $u . '!</h1><br><p>Activate<br><p>Alternatively copy and paste this link in your browser: <br> <b>Https://localhost' . $vkey . '';
echo "<center><div class='alert success'><strong>Successfully Registered!</strong> Please check your email.</div></center>";
}
//OOPS! Throw $error.
echo $mysqli->error;
}
}
?>
In the beginning, I require the files in my PHPMailer folder, then I start PHPMailer
It stresses me out. Idk the problem. If anybody knows the solution or knows a hint of why it doesn't work that would be great. Thanks.
HTML in same file
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
.alert {
padding: 20px;
background-color: #f44336;
color: white;
opacity: 1;
transition: opacity 0.6s;
margin-bottom: 15px;
font-family: Sans-Serif;
border-radius: 15px;
}
.alert.success {background-color: #4CAF50;}
.alert.info {background-color: #2196F3;}
.alert.warning {background-color: #ff9800;}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
</style>
</head>
<body>
<form method="POST" action="">
<table border="0" align="center" cellpadding="5">
<tr>
<td align="right">Username:</td>
<td><input type="TEXT" name="u" required/></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="PASSWORD" name="p" required/></td>
</tr>
<tr>
<td align="right">Repeat Password</td>
<td><input type="PASSWORD" name="p2" required/></td>
</tr>
<tr>
<td align="right">Email Address</td>
<td><input type="EMAIL" name="e" required/></td>
</tr>
<td colspan="2" align="center"><input type="SUBMIT" name="submit" value="Register" required/></td>
</table>
</form>
<center>
<?php
echo $error ;
?>
</center>
</body>
</html>
you can probably try this
i also had an error so i had to add this line before the host
$mail->SMTPOptions=array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false,'allow_self_signed'=>false));
but if that does not work you can try trobleshooting like this
if($mail->Send()){
}else{
var_dump($mail);
die();
}
so once you get your error logs you can probably do a google or paste your error log and maybe we can help

How to send data in email using HTML table & php

I'm trying to send data from database in the form of a HTML table when user click submit button. I'm able to receive the email but only table received. It doesn't seem database data. I want to email a table with data in database. Here is my code.
<?php
require '../Mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
//$mail->SMTPSecure = 'tls';
//$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Port = ;
$mail->Username = '';
$mail->Password = '';
$mail->setFrom('');
$mail->addAddress('');
$mail->isHTML(true);
$mail->Subject = 'Student data';
$body = '<html>
<head>
<title></title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
text-align: left;
padding: 8px;
color:black
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<?php
$username = "root";
$password = "";
$host = "localhost";
$connector = mysqli_connect("$host,$username,$password");
or die("Unable to connect");
echo "Connections are made successfully::";
$selected = mysqli_select_db("school"," $connector");
or die("Unable to connect");
//execute the SQL query and return records
$result = mysqli_query("SELECT*FROM student ");
?>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>age</th>
<th>class</th>
<th>address</th>
<th>comment</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $result ) ){?>
<tr>
<td><?php echo $row["id"] ?></td>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["age"] ?></td>
<td><?php echo $row["class"] ?></td>
<td><?php echo $row["address"] ?></td>
<td><?php echo $row["comment"] ?></td>
</tr>
<?php }
?>
</tbody>
</table>
<?php mysql_close($connector); ?>
</body>
</html> ';
$mail->Body = $body;
//send the message, check for errors
if (!$mail->send()) {
echo "ERROR: " . $mail->ErrorInfo;
} else {
echo "SUCCESS";
}
Thanks for everyone, who answer to my question. Here is the working code for my system.
<?php
require '../Mailer/PHPMailerAutoload.php';
$username = "root";
$password = "";
$host = "localhost";
$connector = mysql_connect($host,$username,$password)
or die("Unable to connect");
echo "Connections are made successfully::";
$selected = mysql_select_db("school", $connector)
or die("Unable to connect");
//execute the SQL query and return records
$result= mysql_query("SELECT * FROM student ORDER BY id DESC limit 1");
$mail = new PHPMailer;
$mail->isSMTP();
//$mail->SMTPSecure = 'tls';
//$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Port = ;
$mail->Username = '';
$mail->Password = '';
$mail->setFrom('');
$mail->addAddress('');
$mail->isHTML(true);
$mail->Subject = 'Student Data';
$body = "<html>
<head>
<title>Student Data</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
text-align: left;
padding: 8px;
color:black
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Age</th>
<th>Class</th>
<th>Address</th>
<th>comment</th>
</tr>
</thead>
<tbody>";
while( $row = mysql_fetch_assoc( $result ) ){
$body.= "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['age']."</td>
<td>".$row['class']."</td>
<td>".$row['address']."</td>
<td>".$row['comment']."</td>
</tr>";
}
$body.="</tbody></table></body></html>";
?>
<?php mysql_close($connector); ?>
<?php
$mail->Body = $body;
//send the message, check for errors
if (!$mail->send()) {
echo "ERROR: " . $mail->ErrorInfo;
} else {
echo "SUCCESS";
}
?>
Above your mysql connection data ($username, ...) is still a php opening tag.
Your code is all wrong, you're opening php tags inside a php tag.
Also you were using mysqli_ the wrong way, then trying to close with mysql_ .
Here, I fixed it for you:
<?php
require '../Mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
//$mail->SMTPSecure = 'tls';
//$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Port = ;
$mail->Username = '';
$mail->Password = '';
$mail->setFrom('');
$mail->addAddress('');
$mail->isHTML(true);
$mail->Subject = 'Student data';
$body = '<html>
<head>
<title></title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
text-align: left;
padding: 8px;
color:black
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
';
$username = "root";
$password = "";
$host = "localhost";
$connector = mysqli_connect($host,$username,$password, "school");
or die("Unable to connect");
echo "Connections are made successfully::";
//execute the SQL query and return records
$result = mysqli_query($connector, "SELECT*FROM student ");
$body .='
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>age</th>
<th>class</th>
<th>address</th>
<th>comment</th>
</tr>
</thead>
<tbody>';
while( $row = mysqli_fetch_assoc($connector, $result ) ){
$body .= "<tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['age']}</td>
<td>{$row['class']}</td>
<td>{$row['address']}</td>
<td>{$row['comment']}</td>
</tr>"
}
$body .='
</tbody>
</table>
</body>
</html> ';
$mail->Body = $body;
//send the message, check for errors
if (!$mail->send()) {
echo "ERROR: " . $mail->ErrorInfo;
} else {
echo "SUCCESS";
}

Unable to send email content using PHPMailer

I am creating an e-commerce website that sends email about order detail after user have checked out. I've succeeded in sending email using PHPMailer. However, the content of email I've sent is being escaped.
How do I ensure that the order detail is being processed properly like the image below?
This is the phpmailer code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - SMTP test</title>
</head>
<body>
<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set("Asia/Singapore");
require '../PHPMailerAutoload.php';
include ('../test.php');
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.gmail.com";
//enable this if you are using gmail smtp, for mandrill app it is not required
$mail->SMTPSecure = 'ssl';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "GMAIL.COM";
//Password to use for SMTP authentication
$mail->Password = "PASSWORD";
//Set who the message is to be sent from
$mail->setFrom('popo#shop.com', 'POPO ECOMMERCE');
//Set an alternative reply-to address
$mail->addReplyTo('popo#shop.com', 'POPO ECOMMERCE');
//Set who the message is to be sent to
$mail->addAddress($email, $user);
//Set the subject line
$mail->Subject = 'Order Details';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('order.php'), dirname(__FILE__));
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
$mail->XMailer = ' ';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
Message code:
<?php
include("../include/db.php");
$user= $_SESSION['id'];
?>
<?php
echo
"<div style='width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 15px;'>
<h1>Order Details</h1>
";
echo
"<p>Dear <b style='color:blue;'>$user</b>, you have ordered the following products from our website: popo.
Below are the details of your order. We will be shipping the products to your address in two weeks.
<br><br>
Thank you for using POPO.
<Br><br><br>
Order Details: <br></p>";
echo '
<table width = "1093" align="center" bgcolor="silver">
<tr align="center">
<th>S.N</th>
<th>Product ID</th>
<th>Invoice ID</th>
<th>QTY</th>
</tr>';
$get_pro =$db->prepare( 'select Product_ID,invoice_id,qty from orders where userid = ?');
$get_pro->bind_param('s',$user);
$get_pro->execute();
$get_pro->bind_result($pro_title,$pro_id,$pro_qty);
$i =0 ;
while ($get_pro->fetch())
{
$i++;
?>
<?php
echo "
<tr align='center'>
<td> $i</td>
<td> $pro_title</td>
<td> $pro_id</td>
<td>$pro_qty</td>
</tr>";
?>
<?php } ?>
<?php echo "</table>"?>
file_get_content() does not execute php script. You need to replace:
$mail->msgHTML(file_get_contents('order.php'), dirname(__FILE__));
by
ob_start();
include "order.php";
$message = ob_get_clean();
$mail->msgHTML($message);
dont load the order.php with file_get_contents() cause this will not execute the php code!
include the file like this:
ob_start();
include("order.php");
$message = ob_get_contents();
ob_end();
$mail->msgHTML($message);
Try replacing the messege code to this:
<?php
include("../include/db.php");
$user = $_SESSION['id'];
echo "<div style='width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 15px;'>
<h1>Order Details</h1>";
echo "<p>Dear <b style='color:blue;'>$user</b>, you have ordered the following products from our website: popo.
Below are the details of your order. We will be shipping the products to your address in two weeks.
<br>
<br>
Thank you for using POPO.
<Br><br><br>
Order Details: <br></p>";
echo '
<table width = "1093" align="center" bgcolor="silver">
<tr align="center">
<th>S.N</th>
<th>Product ID</th>
<th>Invoice ID</th>
<th>QTY</th>
</tr>';
$get_pro = $db->prepare('select Product_ID,invoice_id,qty from orders where userid = ?');
$get_pro->bind_param('s',$user);
$get_pro->execute();
$get_pro->bind_result($pro_title,$pro_id,$pro_qty);
$i = 0;
while ($get_pro->fetch())
{ $i++;
echo "<tr align='center'>
<td> $i</td>
<td> $pro_title</td>
<td> $pro_id</td>
<td>$pro_qty</td>
</tr>";
break;
}
echo "</table>";
?>
And on the other file:
$mail->msgHTML(file_get_contents('order.php'), dirname(__FILE__));
To:
ob_start();
include("order.php");
$message = ob_get_contents();
ob_end();
$mail->msgHTML($message);

How to supress this object(stdClass)#5 (2) { ["errorNumber"]=> int(0) ["scriptResult"]=> object(stdClass)#6 (0) { } }

I am using PHPMailer to send emails from my site based on user inputs.
and I am sung this code. Although I am able to send the email and the required job is done, but, I am getting this on the web page.
object(stdClass)#5 (2) { ["errorNumber"]=> int(0) ["scriptResult"]=> object(stdClass)#6 (0) { } }
I am using gmail to send my emails. I am very new to PHP.
public function sendorderemail() {
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../mail/PHPMailerAutoload.php';
// Stop error reporting
error_reporting(0);
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
$mail->IsHTML(true);
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "xxx#gmail#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "xxxxxxxx";
//Set who the message is to be sent from
$mail->setFrom('xxx#gmail.com', 'MyCompany A/S');
//Set an alternative reply-to address
$mail->addReplyTo('xxx#gmail.com', 'MyCompany A/S');
//Set who the message is to be sent to
$mail->addAddress('xxxx#MyCompany.dk', 'xxx xxxx');
//$mail->addAddress('xxxxx#MyCompany.dk', 'xxxx xxxx');
if($this->kundeemail != ""){
$mail->addAddress($this->kundeemail,$this->kunderekvirent);
}
//Set the subject line
$mail->Subject = "robot#MyCompany.dk - don't reply.";
//Attach the image files
$mail->addAttachment($this->fil1);
$mail->addAttachment($this->fil2);
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
body,td,th {
font-family: Arial;
font-size: 11px;
}
</style>
</head>
<body>
<p>Tak for din bestilling.<br />
<br />
Du har bestil '.$this->antal.' stk. med følgende oplysninger:<br />'.$this->kommentar.'</p>
<h3>Preview</h3>
<p>Forside:</p>
<p><img class="previewimage" width="250px" style="border:1px solid #cecece; " src="http://web2MyCompany.dk/uploads/'.$this->fil1.'" /></p>
<p>Bagside:</p>
<p><img class="previewimage" width="250px" style="border:1px solid #cecece; " src="http://web2MyCompany.dk/uploads/'.$this->fil2.'" /></p>
<h3>Fakturaadresse</h3>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Firmanavn</th>
<td>'.$this->kundefirmanavn.'</th>
</tr>
<tr>
<td>CVR Nr.</td>
<td>'.$this->kundecvr.'</td>
</tr>
<tr>
<td>Telefon Nr.</td>
<td>'.$this->kundetelefon.'</td>
</tr>
<tr>
<td>Rekvirent</td>
<td>'.$this->kunderekvirent.'</td>
</tr>
<tr>
<td>Adresse</td>
<td>'.$this->kundeadresse.'</td>
</tr>
<tr>
<td>Postnr. & By</td>
<td>'.$this->kundepostnr.' '.$this->kundeby.'</td>
</tr>
<tr>
<td>E-mail</td>
<td>'.$this->kundeemail.'</td>
</tr>
</table>
<h3>Leveringsadresse</h3>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Firmanavn</th>
<td>'.$this->leveringfirmanavn.'</th>
</tr>
<tr>
<td>CVR Nr.</td>
<td>'.$this->leveringcvr.'</td>
</tr>
<tr>
<td>Telefon Nr.</td>
<td>'.$this->leveringtelefon.'</td>
</tr>
<tr>
<td>Rekvirent</td>
<td>'.$this->leveringrekvirent.'</td>
</tr>
<tr>
<td>Adresse</td>
<td>'.$this->leveringadresse.'</td>
</tr>
<tr>
<td>Postnr. & By</td>
<td>'.$this->leveringpostnr.' '.$this->leveringby.'</td>
</tr>
<tr>
<td>E-mail</td>
<td>'.$this->leveringemail.'</td>
</tr>
</table>
<p>Med venlig hilsen</p>
<p>MyCompany A/S</p>
</body>
</html>
';
//Replace the plain text body with one created manually
$mail->AltBody = 'MyCompany A/S';
//send the message, check for errors
if (!$mail->send()) {
echo "Error in Sending Email";
} else {
echo "Email Sent Successfully";
}
}
From what I can see the above posted code does not create the output in your script.
The described output:
object(stdClass)#5 (2) { ["errorNumber"]=> int(0) ["scriptResult"]=> object(stdClass)#6 (0) { } }
is most likely the result of a var_dump (or print_r) somewhere in your code on either a json_decode or mysqli_fetch_object (or some similar function that returns a stdClass).
I suggest you search your script and other 'require' files for "var_dump" and simply remove the offender once you find it.
It looks like var_dump has been used in your code but I cannot see it anywhere in the code you have pasted. Perhaps somewhere else in the code.

Phpmailer image in email issue

I don't know why in mail client of MAC OS X (Mail 6.2) the image display like this:
and other mail clients like gmail, outlook or private the image is correctly and looks like this:
Phpmailer
require_once 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer(true);
$mail->IsSMTP();
try {
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = "mail.com.mx";
$mail->Port = 587;
$mail->CharSet = "UTF-8";
$mail->Username = "soldier#mail.com.mx";
$mail->Password = "password?";
$mail->SetFrom('no-reply#mail.com.mx', 'MA Consulting');
$mail->Subject = 'Subject';
$message = '<div style="border:solid 1px #427696;font-family:Arial;width:650px">
<table style="background:#799db4;border-bottom:solid 1px #427696;width:650px; padding:5px;">
<tbody>
<tr>
<td>
<div style="padding:30px 30px 0;font-size:30px; height: 65px;">
<a style="text-decoration: none; color: #FFF;" href="iq.com.mx/iq" target="_blank">MA Consulting</a>
</div>
</td>
<td style="vertical-align:middle;text-align:right;padding-right:30px">
<img src="../media/Logo-MA.gif" width="120px" height="93px"/>
</td>
</tr>
</tbody>
</table>
</div>
<!-- more code -->';
$mail->MsgHTML($message);
$mail->AddAddress($email, $name);
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
I'm just guessing, since it's hard to test, but I don't think width and height attributes in <img> should include px.
Try to remove them:
<img src="../media/Logo-MA.gif" width="120" height="93"/>
The problem is here:
width="120px" height="93px"
You're specifying px on the width and height attributes. That syntax is only relevant in CSS; the old style HTML attributes are always in pixels (or %), and px should not be specified.

Categories