php html email help? - newsletter

I'm using below code for php html email:
$to = $email;
$subject = 'ABC';
$message = $content;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: ABC <a#b.com>'."\r\n";
mail($to, $subject, $message, $headers); // Send our email
where
$content='<html>
<head>
<title>Thanks</title>
</head>
<body>
<div>
<b>Thanks for your email</b>
</div>
</body>
</html>'
Now the email received contains:
\r\n \r\n \r\n \r\n
\r\n
\r\n Thanks for your email\r\n
\r\n
\r\n
I have read several examples, I'm not doing anything wrong as far as format of header goes.
Can't identify problem, help?
Also, any help suggestions with implementation of e-newsletter would be helpful.

First of all no need to use <Head> tags in a mail formatted in HTML.
Try this:
$content = '<html><body>';
$content .='<div><b>Thanks for your email</b></div>';
$content .='</body></html>';
Or this:
$content = "
<html>
<body>
<div>
<b>Thanks for your email</b>
</div>
</body>
</html>";
One of them will do the trick.

may be\n\r are interpreted as Encoded HTML Text .. so use html tags <br> and see for \n

Related

PHP string help mail

hi need some help with mailing. I'm trying to insert the content of this variable into a string to send as an email also need to add a newline. Also need to change From header to "Procity" and procitystaff#gmail.com
$claim_msg='Hey $claim_username, \n The donator has cancelled your claimed item, but you got your ' $email_to=$claim_email;
$template=$claim_msg;
$subject= "Claimed item canceled";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1 '.' \r\n';
$headers .= 'From: procitystaff#gmail.com'.' \r\n';
$from='procitystaff#gmail.com';
mail($email_to,$subject,$template,$headers);
You're missing a semi-colon before $email_to which would cause a syntax error.
You're also using single-quotes ' while inserting a php variable printing out Hey $claim_username as opposed to double-quotes " which would print Hey JohnDoe.
The semi-colon was missing at the end of the first line in the code below. Plus, I also used concatenates.
Give this a try. There will be a line break between the username and The donator.
Example:
Hey John,
The donator has cancelled your claimed item, but you got your
$claim_msg='Hey ' . $claim_username . ',' . "<br>\n" . 'The donator has cancelled your claimed item, but you got your';
$email_to=$claim_email;
$template=$claim_msg;
$subject= "Claimed item canceled";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1 '.' \r\n';
$headers .= 'From: Procity <procitystaff#gmail.com>' . "\r\n";
$from='procitystaff#gmail.com';
mail($email_to,$subject,$template,$headers);

Email attachment works fine in gmail but not on my mailserver

Using PHP i am sending email attachment on both my gmail and mailserver id(company email id). I am getting email in both of my email account but on my company email id my email attachment shows error(it doesn't open properly) whereas in gmail it is fine.
Any ideas or suggestion??
I am pasting my php code here. any help would be highly appreciated.
HTML CODE:
<form action="contact.php" method="post" name="form1" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="fileAttach" id="file"><br><br>
<input type="submit" name="submit" value="Submit" align="right">
</form>
contact.php:
<?php
if($_POST['submit'])
{
$strTo = "mymail#company.com, mymail#gmail.com";
$strSubject = "Attachment file";
$strMessage = "Attachment";
$txtFormEmail = "mymail#gmail.com";
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: "."<".$txtFormEmail.">\nReply-To: ".$txtFormEmail."";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$strFilesName = $_FILES["fileAttach"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
$flgSend = mail($strTo,$strSubject,$strMessage,$strHeader);
}
?>
You can use PHP Mailer Class to send mails with attachments.

PHP Form fields will not send to email

I have created a send to email PHP script.
The form seems to work correctly when sending only one field (the message field) but as soon as other fields are added, the form ceases to be emailed on to the inbox (yet the form still fires correctly and reroutes to the thankyou just fine.)
Here is the code I currently have, this does not work
<?php
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$services = $_REQUEST['services'] ;
$message = $_REQUEST['message'] ;
if (!isset($_REQUEST['email'])) {
header( "Location: feedback.html" );
}
elseif (empty($email) || empty($message)) {
header( "Location: error.html" );
}
else {
mail( "info#website.co.uk", "Message via your website!",
$name, $services, $message, "From: $email" );
header( "Location: thankyou.html" );
}
?>
This is the previous code, this does work, but only displays the message
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
if (!isset($_REQUEST['email'])) {
header( "Location: feedback.html" );
}
elseif (empty($email) || empty($message)) {
header( "Location: error.html" );
}
else {
mail( "info#website.co.uk", "Message via your website!",
$message, "From: $email" );
header( "Location: thankyou.html" );
}
?>
This is the HTML for the form:
<form method="post" action="sendmail.php">
<label>Name:</label> <input name="name" type="text" /><br />
<label>Email:</label> <input name="email" type="text" /><br />
<label>What service do you require?:</label> <input name="services" type="text" /><br />
<label>Message:</label><br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
As per the mail() docs the message body should be passed as a single parameter. So it should look something more like:
mail( "info#website.co.uk", "Message via your website!", "$name\r\n $services\r\n $message", "From: $email");
According to php.net the correct use of the mail() function is:
<?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
You are trying to send the additional data ($services) as a header.
Try to merge your $message and $service >
$message = $service . "\r\n\r\n" . $message;
mail( "info#website.co.uk", "Message via your website!",
$message, "From: $email" );
You can't just add more and more variables to mail(). There is only one parameter that specifies the content of the email, which would be the third one, as you can see in the official documentation:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
If you want to have more than just $message in your mail, you need to put everything into one variable to be given to the function as content.
$content = $message;
$content .= "\n" . $services;
// etc...
mail($to, $subject, $content);
Try this
<?php
$email = $_POST['email'] ;
$name = $_POST['name'] ;
$services = $_POST['services'] ;
$message = $_POST['message'] ;
if (!isset($_POST['email'])) {
header( "Location: feedback.html" );
}
elseif (empty($email) || empty($message)) {
header( "Location: error.html" );
}
else {
mail( "info#website.co.uk", "Message via your website!",
$name . $services. $message . "From: $email" );
header( "Location: thankyou.html" );
}
?>

Change the Return-Path in PHP mail function

Is it possible to change the Return-Path value in emails are sending via mail() function of PHP ?
It's value is 'www-data#mydomain.com' in emails I send in my site and it causes some problems on email delivery failed process. I want to set it to my email address.
Here's the code I have tried:
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\n";
$headers .= "Return-Path: <adminemail#yahoo.com>"."\n";
$headers .= "Errors-To: <adminemail#yahoo.com>"."\n";
// Additional headers
$headers .= "To: email1#yahoo.com <adminemail#yahoo.com>" . "\n";
$headers .= "From: adminemail#yahoo.com <adminemail#yahoo.com>";
// Mail it
mail('email1#yahoo.com', 'test', 'salam', $headers, "f");
You can set reply to & return path into headers as below
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'Return-Path: webmaster#example.com'
OR
as the fifth parameter to adjust the return path
mail($to, $subject, $message, $headers, "-f email#wherever.com");
where email#wherever.com should be replaced by your mail.
The issue is mail format requires headers to use \r\n line endings... not \n, the trick with that is some servers will accept both (convert them for you and it seems to work magically) while others will consider those without \r\n endings to be invalid and basically ignore all your headers. So try instead:
$headers = "MIME-Version: 1.0\r\n".
"Content-type: text/html; charset=utf-8\r\n".
"Return-Path: adminemail#yahoo.com";
mail ("email1#yahoo.com","test","salam",$headers);
By the way, return-path expects an RFC1123 mailbox (without the angle brackets, just the email address) ... not sure why you'd want to set return-path as in your example since it's the same as the from address (so superfluous)
Just define Return-Path
$returnPath = "-fadminemail#yahoo.com"; //-f will do the job
mail('email1#yahoo.com', 'test', 'salam', $headers, $returnPath);

Why my html code also display when i send email?

hi dear this is my code to send email
my message code is this
$to = $email;
$subject = "Activation";
$message = "Your activation key is this " .$key.'<br>'.' click here to activate your acount. here';
$from = "riaz_qadeer90#yahoo.com";
$headers = "From:" . $from;
if(mail($to,$subject,$message,$headers))
{
echo "Check your email to activate your acount.";
}
The problem is this when i send email the whole message shown in my inbox with code. why it not show "Click" as an anchore.....
Mail isn't HTML format by default, so it's sending this as plain text. See Example #4 on the PHP page for mail() for sending HTML email. You need to specify the content type for the message headers:
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Note the .= operator being used here. You'd be appending this to your existing $headers value. So you'll also want to make sure your existing header is terminated properly:
$headers = "From:" . $from . "\r\n";
You have to check following things:-
1>message content properly it has enclosed with which inverted comma,either ' or ".
2>check your header and additional header information properly concatenate with (.) operator or not.
Most of the time problem arrives in second case.
$headers .= 'To: abc, bcd' . "\r\n";
$headers .= 'From:xyz ' . "\r\n";
Because you must define the header of your e-mail as HTML.
http://www.w3schools.com/php/func_mail_mail.asp