Hi I am trying to send an entire webpage via e-mail. I receive it in Mail.app in my Mac and i can see it fine. But when i see it in gmail or hotmail, It didn't get the styles
How can I do this correctly. Or how to transform the webpage to PDF or PNG and send it via Mail [I can't install anything to the server]
Edit: It send all the information but without Style
My code:
$mail = $_POST['mail'];
if(($Content = file_get_contents("http://google.com")) === false) {
$Content = "";
}
$Headers = "MIME-Version: 1.0\n";
$Headers .= "Content-type: text/html; charset=iso-8859-1\n";
$Headers .= "From: a#a.com <a#a.com>\n";
$Headers .= "Reply-To: a#a.com\n";
$Headers .= "X-Sender: <a#a.com>\n";
$Headers .= "X-Mailer: PHP\n";
$Headers .= "X-Priority: 1\n";
$Headers .= "Return-Path: <a#a.com>\n";
if(mail($mail, $subject, $Content, $Headers) == false) {
//Error
}
Thanks
Remove all external style sheets . All the styles on the page should be inline or defined within the page
Related
I want to convert the link to the button in PHP mail.php file.
$message = sprintf($this->language->get('mail_message'), $store_name, $link);
I will appreciate if someone helps me to convert the link to the button.
To achieve this, you have to send html email instead of plain/text email. It is pretty simple, leave the images on the server and send the PHP + CSS to them...
$to = 'xyz#example.com';
$subject = 'Subject';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: abc#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<p>Anchor Text</p>';
mail($to, $subject, $message, $headers);
We've recently upgraded to a Plesk Parallel Linux Server and it appears as if the PHP settings are ignoring headers! The emails are receiving fine, but display the HTML tags.
The phpInfo() file can be viewed here: https://www.pressgofer.com/phpInfo.php
The PHP itself should be okay, but have included it here anyway.
PHP Mail Code
$email = "example#example.com";
$message = "<h1 style='font-family:Helvetica,Arial;font-size:17px'>Your account has a password reset request</h1>";
$headers = "From: noreply#pressgofer.com \r\n";
$headers .= "Reply-To: noreply#pressgofer.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($email, "Reset password notification", $message, $headers);
Many thanks,
Nick
your phpinfo shows that mail.add_x_header is OFF. you need to turn it on
To enable the X-Mail header, set mail.add_x_header to 1 in your php.ini
<?php
$to = "yourplace#somewhere.com";
$subject = "My HTML email test.";
$headers = "From: sinha.ksaurabh#gmail.com\r\n";
$headers .= "Reply-To: sinha.ksaurabh#gmail.com\r\n";
$headers .= "Return-Path: sinha.ksaurabh#gmail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "<h1> This is a test </h1>";
$message .= "</body></html>";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
sending mail from php: headers are interpreted as body?
Issue was associated with MIME type and server interpretation- no \r needed.
I am trying to dynamically send text messages using a PHP script. PHP code:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$textbody=<<<_MESSAGE_
Some text
_MESSAGE_;
mail('myphonenumber#SMSgateway','subject',$textbody,$headers);
I did receive a text message, but it is a "photo message" or rather multimedia instead of text and I am unable to open the message. I have tried playing around with the encoding and $textbody="this text"; instead of *MESSAGE*.
a) How can I send a normal text message (not multimedia)?
b) Why can't I open it?
c) Is there a way for people to respond to the texts I send with text? When I sent myself a text from hotmail I was able to reply and I got the answer in my inbox. When I tried to put $header.= 'From: me <me#somedomain.com>' . "\r\n"; the email wouldn't send
(reason: 553 sorry, your mail was
administratively denied. (#5.7.1))
Thanks!
$sendTo = "test#test.com";
$subject = trim($_POST['subj']);
$headers = "From: ".$_POST['name']."<" . trim($_POST["email"]) .">\r\n";
$headers .= "Reply-To: " . trim($_POST["email"]) . "\r\n";
$headers .= "Return-path: " . trim($_POST["email"]);
$headers .= "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$message = strip_tags($_POST["messg"]);
if (#mail($sendTo, $subject, $message, $headers))
{ echo "sent successfully"; }
else
{ echo "Error ... Plz try again later" ; }
This code which I'm using to send emails
I worked before on SMS project so if you have any question about how to link with Getaway feel free to contact me
I have this logic
$subject = "something.com Signup -
Please do not reply to this email. It was automatically generated.";
$body = "A new person has signed up to receive something updates:";
$headers = "From: webinquiries#something.com\n";
$headers .= "Reply-To: something#gmail.com\n";
// $headers .= 'Bcc: something#something.com' . "\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\n";
mail($email, $subject, $body, $headers);
which seems ok but one thing.... can i set the smtp info like this
server="smtp.something.net",
username="webinquiries#somthing.com",
password="asda.1sda",
port="587"
you can set the server in php.ini, but user\password as php's build in mail does not support authentication. you should look at a third party library (phpmailer) as the php mail() function's very under powered.
as in asp we have function to send complete web page in email, which basically save lot of time for developer in creating & sending email
see the following code
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="xxx#example.com"
myMail.To="xxx#example.com"
myMail.CreateMHTMLBody "mywebpage.html",cdoSuppressNone
myMail.Send
set myMail=nothing
%>
as we know that CreateMHTMLBody will get data from mywebpage.html and send it as a body of email.
i want to know does any function like (CreateMHTMLBody) this is available in php ?
if Not can we crate any function if yes, please give me some hints.
Thanks
Example below:
<?
if(($Content = file_get_contents("somefile.html")) === false) {
$Content = "";
}
$Headers = "MIME-Version: 1.0\n";
$Headers .= "Content-type: text/html; charset=iso-8859-1\n";
$Headers .= "From: ".$FromName." <".$FromEmail.">\n";
$Headers .= "Reply-To: ".$ReplyTo."\n";
$Headers .= "X-Sender: <".$FromEmail.">\n";
$Headers .= "X-Mailer: PHP\n";
$Headers .= "X-Priority: 1\n";
$Headers .= "Return-Path: <".$FromEmail.">\n";
if(mail($ToEmail, $Subject, $Content, $Headers) == false) {
//Error
}
?>
To add to Erik's answer, if you want to import a local (or remote!) file instead of specifying the HTML in the code itself, you can do this:
// fetch locally
$message = file_get_contents('filename.html');
// fetch remotely
$message = file_get_contents('http://example.com/filename.html');
Use the output buffer functions of PHP and include the desired webpage. Example:
// Start output buffering
ob_start();
// Get desired webpage
include "webpage.php";
// Store output data in variable for later use
$data = ob_get_contents();
// Clean buffer if you want to continue to output some more code
// in which case it would make sense to use this functionality in the very beginning
// of your page when no other code has been processed yet.
ob_end_clean();
Here's how:
$to = 'joe#example.com';
$subject = 'A test email!';
// 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";
// Put your HTML here
$message = '<html><body>hello world</body></html>';
// Mail it
mail($to, $subject, $message, $headers);
You've just sent HTML email. To load an external HTML file replace $message = '' with:
$message = file_get_contents('the_file.html');