how to send email template html page? - phpmailer

Im using PHPMAILER 5.2.7 !
$to=$row['email'];
$at=$row['updated_at'];
$subject = "Your Password has been changed";
$body = "<body background='red' style='bgcolore:red;'><p>Hello < ".$u." > your password has been
changed at ".$at." ! </p>";
$SITEEMAIL='support#test.tn';
$mail = new Mail();
$mail->setFrom($SITEEMAIL);
$mail->addAddress($to);
$mail->subject($subject);
$mail->body($body);
$mail->send();
how can i switch the $body content with a html page (template) ?? tried to directly past the code inside $body but i dosen't work !

I see several strange things in your $body text, try using more simple contents from this sample first. github.com/PHPMailer/PHPMailer#a-simple-example
In any case, you should also call $mail->isHTML(true); before sending.

Related

DirectAdmin API - issue with show user config

<?php
include '../protocol/httpsocket.php';
$sock = new HTTPSocket;
$sock->connect('localhost',2222);
$sock->set_login('admin','admin_password');
$show_user='user5';
$sock->query('/CMD_API_SHOW_USER_CONFIG?user='.$show_user);
$result = $sock->fetch_parsed_body();
print_r($result);
?>
This above code return:
white page with only "Array ( )"
Connection with DA is correct, because I can create user API etc.
Try add $sock->set_method('POST'); or $sock->set_method('GET'); after $sock->set_login('admin','admin_password');

change font size for phpmailer subject

The following function works but I am unable to control the font-size of the "Subject". Is there a way to change the font size of the "Subject". I've tried:
$mail->Subject = "<span style='font-size:3vw'>" .$mailInputs['subject'] ."<\span>";
but that didn't work.
function mailerExpressBlueHost(array $mailInputs){
require_once '../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsMail();
$mail->SetFrom('example#xyz.com');
$mail->IsHTML(true);
$mail->addAddress('abc#example.com');
$mail->AddEmbeddedImage("../public/img/swb.jpg", "swb-image");
$body = '<!DOCTYPE html>
<html><header>
</header>
<body lang=EN-US>
<div style="text-align:center">
<img src="cid:swb-image">' . $mailInputs['body'] ;
$mail->isHTML(true);
$mail->Subject = $mailInputs['subject'] ;
$mail->Body = $body;
if(!$mail->send()) {
return 'Message could not be sent.' . 'Mailer Error: ' . $mail->ErrorInfo;
} else {
return 'Message has been sent';
}
$mail->ClearAddresses();
}
No, you can't do this. The Subject line does not support HTML formatting; it's plain text only - not least because the definition of the Subject email header predates HTML by at least 10 years.
On the upside, you can use unicode, which allows you quite a lot of tricks, but it's highly dependent on the OS and application it's viewed in.

phpmailer for php variables

I am running phpmailer and very much new to it.
Problem definition: Not able to see php variables data in the received email while html content can seen properly.
Below is some of the code:
require 'PHPMailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Message';
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong> <?php echo "$name";?> <?php echo "$place";?>
</body>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
Not able to see data defined under php.
Also $name and $place is the dynamic data for the every mail.
Please help.
You cannot put php statements in single quotes. use the following instead:
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>' . $name . ' ' . $place . '
</body>';
You need to put the text between " instead of '.
PHP only replaces variables in double quoted strings.
Also you shouldn't use php code in the strings.
$mail->Body = "
<body>
<div align=\"center\"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong> $name $place
</body>
";
try instead :
$mail->Body = "<body>
<div align=\"center\"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>$name $place
</body>";
You don't have to put php tags in your string since you are already in a php context !
Replace Body with :
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>'.$name.' '.$place.'</body>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message .= "Phone: 0181-4606260.<br>";
$message .="Mobile :09417608422.<br>";
Send_Mail('abc#example.com','Welcome',$message,$headers);
try this...

GMail doesn't mark up email html (sending via PHP)

I am trying to send a html email via mail(), however gmail just displays the email as plain text, no mark up, eg:
mail("blah#blah.com", "<i>Italic Text</i>");
just appears as
<i>Italic Text</i>
Any ideas?
Have you set your email headers?
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
If yes, do any other email clients have the same problem? Or is it just Gmail?
Try it with css, the i tag is deprecated, not sure if that is causing it...
<span style='font-style:italic;'>Italic Text</span>
Or you could try using the em tag:
<em>Italic Text</em>.

How to send HTML email in drupal 6 using drupal_mail?

How to send HTML email in drupal 6 using drupal_mail ? How can I change HTML header to show email contents in HTML.
You can to set the header in hook_mail_alter()
<?php
hook_mail_alter(&$message) {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
}
?>
i know this may be late, but it may help others. Its better to use drupal_mail and then set the headers in hook_mail instead of hook_mail alter. an example would be like:
/*drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)
Lets say we call drupal_mail from somewhere in our code*/
$params = array(
'subject' => t('Client Requests Quote'),
'body' => t("Body of the email goes here"),
);
drupal_mail("samplemail", "samplemail_html_mail", "admin#mysite.com", language_default(), $params, "admin#mysite.com");
/*We now setup our mail format, etc in hook mail*/
function hook_mail($key, &$message, $params)
{
case 'samplemail_html_mail':
/*
* Emails with this key will be HTML emails,
* we therefore cannot use drupal default headers, but set our own headers
*/
/*
* $vars required even if not used to get $language in there since t takes in: t($string, $args = array(), $langcode = NULL) */
$message['subject'] = t($params['subject'], $var, $language->language);
/* the email body is here, inside the $message array */
$body = "<html><body>
<h2>HTML Email Sample with Drupal</h2>
<hr /><br /><br />
{$params['body']}
</body></html>";
$message['body'][] = $body;
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
break;
}
If this is unclear to you, a complete tutorial on this can be found on My Blog
Hope this helps
JK

Resources