Given an email as raw text, how can I send it using PHP?
I had the same problem but found a solution that seams to work. Open a socket in PHP and "telnetting" the raw emaildata. Something like this:
$lSmtpTalk = array(
array('220', 'HELO my.hostname.com'.chr(10)),
array('250', 'MAIL FROM: me@hostname.com'.chr(10)),
array('250', 'RCPT TO: you@anotherhost.com'.chr(10)),
array('250', 'DATA'.chr(10)),
array('354', $lTheRawEmailStringWithHeadersAndBody.chr(10).'.'.chr(10)),
array('250', 'QUIT'.chr(10)),
array('221', ''));
$lConnection = fsockopen('mail.anotherhost.dk', 25, $errno, $errstr, 1);
if (!$lConnection) abort('Cant relay, no connnection');
for ($i=0;$i<count($lSmtpTalk);$i++) {
$lRes = fgets($lConnection, 256);
if (substr($lRes, 0, 3) !== $lSmtpTalk[$i][0])
abort('Got '.$lRes.' - expected: '.$lSmtpTalk[$i][0]);
if ($lSmtpTalk[$i][1] !== '')
fputs($lConnection, $lSmtpTalk[$i][1]);
}
fclose($lConnection);
You might need to lookup the mx-host if you dont know it. Google has an answer to that i'm sure.
Phpmailer sending email as plain text to emails
The issue was solved by enabling smtp login details
HTML emails sends as plain text with PHP
It seems from that somehow there are extra line breaks between each two lines of your headers. How it manages to happen, I'm not sure, as your code doesn't put them there. It's possible that the receiving mail server is messed up somehow and interprets \r\n
as two line breaks instead of one. To start with, I would remove \r
leaving only \n
in and see what happens. I know this is not proper per RFC - but start with that.
To make you feel better, I am using a very similar code - and the email gets delivered correctly.
Sending Plain text emails using PHPMailer
You are setting $mail->MsgHTML()
to a plain text message, and since whitespace formatting is ignored in HTML, you're getting an inline text.
I haven't used PHPMailer for a while, but from memory try:
$mail->Body = file_get_contents($newFile);
Send HTML in email via PHP
It is pretty simple. Leave the images on the server and send the PHP + CSS to them...
$to = 'bob@example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
It is this line that tells the mailer and the recipient that the email contains (hopefully) well-formed HTML that it will need to interpret:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
Here is the link I got the information from... (link)
You will need security though...
How can I send an email using PHP?
It's possible using PHP's mail()
function. Remember the mail function will not work on a local server.
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Reference:
PHP - Plain text email
Removing the HTML should do the trick but you'll probably want to change the content-type to text/plain as well:
."Content-Type: text/plain; charset=\"utf-8\"\r\n"
(I would have let a comment suffice but I can't post comments yet :))
Related Topics
Best Way to Handle Dirty State in an Orm Model
Strtolower() for Unicode/Multibyte Strings
How to Recursively Obtain the "Parent Id" of Rows in This MySQL Table
PHP Loop Through Associative Arrays
Getimagesize() Not Returning False When It Should
Calling PHP Function from Jquery
Sqlite Database Hosted on Heroku Getting Automatically Reset
Codeigniter PHP Stylesheet Link. How
Add Custom User Email to Cc for Specific Woocommerce Email Notification
Sqlstate[Hy000] [2003] Can't Connect to MySQL Server on '127.0.0.1' (61) Error Laravel 4.1
Sparql Query to Get All Parent of a Node
Installing Mcrypt on Osx 10.8.2 - PHP 5.3.15 with Homebrew
Htaccess Rule to Parse PHP in HTML Files Not Working
How to Change the Sequence of 'Joins' in Cakephp
How to Convert an Iso8601 Date to Another Format in PHP