I am trying to send an mail formatted as html formatting and containing an image. The image is on my server and I have given the path to it in the html code. The problem is, the email is sent as text only and does not contain the image or any formatting.
The code:
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet">
<?php
$mg_api = 'key-3ax6xnjp29jd6ere4gc373sgvjxteol0';
$mg_version = 'api.mailgun.net/v2/';
$mg_domain = "samples.mailgun.org";
$mg_from_email = "ping@test.com";
$mg_reply_to_email = "ping@test.com";
$mg_message_url = "https://".$mg_version.$mg_domain."/messages";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt ($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_VERBOSE, 0);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, 'api:' . $mg_api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $mg_message_url);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array( 'from' => 'Test <' . 'Test_it@yahoo.com' . '>',
'to' => 'test.it@gmail.com',
'h:Reply-To'=> ' <' . $mg_reply_to_email . '>',
'subject' => 'Thanks for you interest ...',
'html' => '<html> <body> <strong> Welcome </strong> <img src="logobeta.png" class="img-responsive" alt="Responsive image"> <div id="footer">
<div class="container">
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">What is facebook?</a></li>
<li><a href="#about">How does it work?</a></li>
<li><a href="#contact">Feedback</a></li>
<li><a href="#contact">Contact us</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</body> </html>'
));
$result = curl_exec($ch);
curl_close($ch);
$res = json_decode($result,TRUE);
print_r($res);
?>
Update for phpmailer:
In phpmailer I got Mailer Error: SMTP connect() failed.
error.
My proble is what should be Host
, username
, password
. It is talking about which credentials?
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted