php html create email and print in landscape - php

In PHP I have the following code that sends an email. Is there someway to encode it so that the email, when printed by the recipient, automatically prints in landscape?
$email_subject = 'Crew List';
// instantiate mailer
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "xxxxxx#gmail.com";
$mail->Password = "xxxxxx";
$mail->SetFrom("yyyyyy#gmail.com"); // set From:
$mail->AddAddress("zzzzzz#gmail.com"); // set To:
$mail->Subject = $email_subject; // set Subject:
$body = $msg;
* $mail->MsgHTML($body);
if ($mail->Send() === false)// send mail
{
apologize_index("Google was not able to connect, try again later");
}
$mail->ClearAddresses();

I have a solution you may have a try:
Most of the email clients in this world supports HTML format. so you may use CSS to have a try.
Please have a look:
Landscape printing from HTML
So, generate your email as HTML format, and combine those CSS.
The support for email clients is very mixed.
OR, why not just generate a landscape PDF as an attachment?

I think that's good option to make your email in the pdf format which should be in the landscape orientation.

Related

PHPMailer When Displayed Received/Sent Emails On Native Mobile Client Reader The Email Doesn't Display Correctly?

I'm working with the PHPMailer and I'm having a small issue with the output of the email when read on a native mobile email. When displayed on a desktop the email displays perfectly as expected. However, when I try reading them via a native email reader such as the pre-installed "Mail" apps on iPhone or Android the emails display letter by letter going vertically, example below:
Display on Native Mobile Apps
2
0
/
0
8
/
2
0
1
8
Display on Desktop or Gmail Mobile App:
20/08/2018
Has anyone experienced this issue, as I have no idea why this would happen, it does this with the entire email? But strangely only with the native email apps, as when read through Gmail it displays fine.
Thanks in advance.
Code:
<?php
//Get Date
$_todaysDate = new DateTime();
$todaysDate = $_todaysDate->format('d/m/Y');
//Set Email Main Body
$body1 = '<img style="margin-left:25%" src="images/DocHeader.png" width="50%">';
$body2 = '<br>'.$todaysDate;
$body3 = '<br><br>Dear Full Name,<br>';
$body4 = '<br>Email Full Body:';
$body5 = '<br><img style="margin-left:25%" src="images/DocFooter.png" width="50%">';
//Set Email Main Body (Footer)
$footer1 = '<strong>Email From</strong>';
$footer2 = '<strong>My Footer</strong>';
//String Together Body & Footer
$body = $body1.'<p style="margin-left:30%;margin-right:25%;">'.$body2.$body3.$body4.$body5.'</p>'.$body19.'<h4>'.$footer1.'</h4><p>'.$footer2.'</p>';
//Start Email
$mail = new PHPMailer(true);
//$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.example.com;'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username#example.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Set Recipients
$mail->setFrom('info#example.com', 'Info');
$mail->addAddress('toEmail#example.com', 'To Name'); // Add a recipient
$mail->addReplyTo('info#example.com', 'Info');
$mail->AddBCC("log#example.com", "Email Logs");
//Set Content
$mail->isHTML(true);
$mail->Subject = 'Email Subject';
$mail->Body = ($body);
$mail->AltBody = '';
if(!$mail->Send()) {
$locationLogin = 'Location: FailedLocation.php';
header($locationLogin);
}
else {
$locationLogin = 'Location: SuccessLocation.php';
header($locationLogin);
}
?>

PhpMailer not working with html

I am using PhpMailer class to send emails that contains html,I noticed that if the body on email contain img tags the email not receiving and no errors showing.
Any suggestions?
my code so far:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "myusername";
$mail->Password = "mypassword";
$mail->setFrom($from);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body =$body;
$mail->IsHTML(true);
if ($mail->send()) {
return 1;
} else {
return 0;
}
if you're trying to send it from localhost and read in gmail, it won't work because gmail often creates proxy image links. you need to send image links that direct to internet-accessible location. That's probably it.
If you're sending email with links to internet-accessible locations, please attach them to the question and I'll update the answer, too.
EIDT: after chat with the asker, it was determined the email HTML was missing normal HTML markup: <html><body>ACTUALCONTENT</body></html>, after adding those,image shown up correctly.
You can use the AddEmbeddedImage method to attach image to your body. So your code should look like this.
$mail->AddEmbeddedImage($_REQUEST['image_name'], 'ImageName');
And then in your $body you can use this image
$body.= "<img src='cid:ImageName' />";

Text sent using php not received

I have a small php website that sends a text message to any given number in US. I tried sending my self a text using it but didn't receive it. I sent it to my cousin's number and he received it. I am using Simple Mobile as my carrier and my cousin uses T-mobile. Could it be that somehow this message is being converted to short message? If so, is there any way I can fix it ? Because in future, I will need to send text messages to any given number and it would be nice if all intended recipients receive the texts without having to enable any thing.
Here is my code :
require 'PHPMailer-master/PHPMailerAutoload.php';
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPDebug = 2; // This will print debugging info
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tls"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Encoding = '7bit'; // SMS uses 7-bit encoding
// Authentication
$mail->Username = "example#gmail.com"; // Login
$mail->Password = "password"; // Password
// Compose
$mail->Subject = "Testing"; // Subject (which isn't required)
$mail->Body = "Testing"; // Body of our message
// Send To
$mail->AddAddress( "phoneNumber#tmomail.net" ); // Where to send it
var_dump( $mail->send() ); // Send!

PHPMailer: hyperlink appears in brackets in outlook

I use phpmailer to send an email with a hyperlink on its body. I have this code:
$body = "<a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a>";
require('classes/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->CharSet = "UTF-8";
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SMTP_HOST; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASSWORD; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom(SMTP_USER);
$mail->addAddress($to); // Add a recipient Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $altbody;
if(!$mail->send()) {
echo $mail->ErrorInfo;
}
When I send the email to a Gmail address and open it in Gmail the hyperlink looks fine (I can click on the link and redirect to the page).
But when I send it to Outlook the hyperlink looks like this:
[my.domain.com/activate.php?x=52&y=aa1fdf437c526ee219decc1ea72fc266]my.domain.com/activate.php?x=52&y=aa1fdf437c526ee219decc1ea72fc266
Any ideas on what might be wrong?
E-mail clients have different rendering engines.
It appears that gmail will render a link without the http:// or https:// protocol.
Outlook may still require it.
Try using a protocol-less (aka scheme-less) URL: //
$body = "<a href='//".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a>";
EDIT:
Note from #Synchro in the comments:
Anonymous/relative protocol URLs are a bad idea in email because
unless you're in a webmail client, you have no base protocol to be
relative to, and so they just break. Make it explicit and it will work
everywhere, and these days it's hard to find a good excuse not to use
https.

How do I delay sending mails with PHPMailer for multiple days?

I'm trying to create a mailing system for our library. People receive an e-mail when they requested a book. However, I want them to receive an e-mail one day before the hand-in date as well.
So I'm not looking for a sleep script code, I'm looking for a code that can maybe store the data on the server until the hand-in date arrived.
I'm using Joomla 3.5.1 for our website, this is the code for the PHPMailer:
jimport('joomla.mail.mail');
try{
$mail = new PHPMailer();
$body = $mailmsgadmin;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "example.host.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "example.host.com"; // sets the SMTP server
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "email"; // SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->SetFrom('email', 'First Last');
$mail->AddReplyTo($mailuseremail, $mailusername);
$mail->Subject = $mailsubject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress("Users e-mail","Users name");
if(!$mail->Send()) {
JError::raiseWarning( 'SOME_ERROR_CODE', $mail->ErrorInfo);
}
} catch (Exception $e) {JError::raiseWarning( 'SOME_ERROR_CODE', $e->getMessage());}
Instead of trying to get PHPMailer delay the sending, add your email details to a database table. And then write a cron job that checks the table for emails that need to be sent.

Categories