I am trying to generate an email on signing up to website, I am using PHP to create and send the email. My domain has both SPF and DKIM running on it. However when i spam check my email i get this:
[SPF] srv61.hosting24.com does not allow your server 31.220.105.111 to use face159#srv61.hosting24.com
[Sender ID] srv61.hosting24.com does not allow your server 31.220.105.111 to use face159#srv61.hosting24.com
Your message is not signed with DKIM
I have contacted my hosting and they confirm that all the authentication systems are working on there end, so i must be doing something wrong in the PHP code but for the life of me i can't find what here is how i generate the email:
//Emails link to voucher
//create a boundary for the email. This
$boundary = uniqid('np');
$subject = "The Forum - Little Thank You";
//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: TheForum#freewifisystems.co.uk" . "\r\n";
$headers .= "To: " . $email . "\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
//here is the content body
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
//Plain Email
$content2 = "plain text email here";
//Plain text body
$message .= "Hello,\nThis is a text email as HMTL is dissable, Please enable HTML to continue. \n\nRegards,\nThe Forum";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
//Html body
$message .= $content3;
$message .= "\r\n\r\n--" . $boundary . "--";
//invoke the PHP mail function
mail($email, $subject, $message, $headers);
?>
$email and $content3 are set via SQL and are setting correctly the email forms and is well formatted.
Related
I have a multi-part email script, that takes a POSTed email address and sends a simple email to them in HTML and/or Plain Text. It displays correctly in Gmail and Outlook, but not eM (and doesn't even get through to a Communigate server). The code:
<?php
$email_address = addslashes($_POST['email_address']);
if (!filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
header("Location: ./?error=invalid-email");
exit();
}
$subject_line = "This is a test multi-part email";
$boundary = uniqid();
$headers = "MIME-Version:1.0\r\n";
$headers .= "From: Maggie Multipart <web#ukipme.com>\r\n";
$headers .= "To: " . $email_address . "\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/plain;charset=utf-8\r\n\r\n";
$message .= "Hello,\nThis is a test email, the text/plain version.\n\nRegards\nMaggie Multipart";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/html;charset=utf-8\r\n\r\n";
$message .= "<p>Hello,<br>This is a test email, the text/html version.</p><p>Regards<br><strong>Maggie Multipart</strong></p>";
$message .= "\r\n\r\n--" . $boundary . "--";
mail("", $subject_line, $message, $headers);
header("Location: ./?success=email-sent");
exit();
// var_dump($_POST);
?>
The message is received in eM as follows:
Content-Type: text/plain;charset=utf-8
Hello,
This is a test email, the text/plain version.
Regards
Maggie Multipart
However, eM is set up to receive HTML emails (and does so frequently). Can someone please help me fix this problem? Am I missing any headers?
My general advice for creating emails: Don't do it yourself (with some string concat functions/operators anyway). My weapon of choice is swiftmailer but there are other feasible libraries on the web, too.
<?php
require_once('autoload.php'); // swiftmailer was installed via Composer
$message = Swift_Message::newInstance('This is a test multi-part email')
->setBody(
"Hello,\nThis is a test email, the text/plain version.\n\nRegards\nMaggie Multipart",
'text/plain',
'utf-8'
)
->addPart(
"<p>Hello,<br>This is a test email, the text/html version.</p><p>Regards<br><strong>Maggie Multipart</strong></p>",
'text/html',
'utf-8'
)
->setFrom(array('...#...' => '...'))
->setTo(array('...#...' => '...'));
$transport = Swift_SmtpTransport::newInstance('MSERV', 25, 'tls')
->setUsername('...')
->setPassword('...');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
i want to send a mail the code is given below. i cant understand waht is happening . It works on localhost but not on live server.
if (isset($_POST['test_mail'])){
$to = '2606ankit#gmail.com'; //put email address on which mail send
$subject = "Newsletter"; //Put subject of mail here
$from = 'ankit#studiokrew.com'; //put email address from
//email body start
// $body .= file_get_contents('file/'.$filename.'');
$body .= 'anio';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: '.$from. "\r\n";
//if you need to send cc mail then uncomment below line and change email address
//$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$body,$headers);
}
try this..
<?php if (isset($_POST['test_mail'])){
$host=$_SERVER['HTTP_HOST'];
$replyto="<no-reply >";
$to ='2606ankit#gmail.com';
$subject = "Newsletter";
$from = 'ankit#studiokrew.com';
$headers = "From: \"Invoice\"<noreply#$host>\n";
$headers .= "Reply-To: ".$replyto."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"abc"\"\r\n\r\n";
$headers .= 'From: '.$from. "\r\n";
$header .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
$body = "This is a multi-part message in MIME format.\r\n";
$body .= "Content-type:text/html; charset=iso-8859-1\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= 'anio';
mail($to,$subject,$body,$headers);
}
?>
check the MTA logs on your server.also web server logs the answer will be there somewhere.
Test with a simple mail() script that does not require any external data, just to make sure that your server indeed can send mail. If that fails, you'd have to contact the server admins for help.
Im trying to remember a trick i was taught a while back but can not.
Basically, im using PHP mail() in this fashion:
$to = "emailAddress1#domain.com";
$subject = "Welcome to BuildSanctuary";
$messageContent = "Thankyou for registering Bla bla bla";
$message = 'SOME HTML EMAIL STUFF including the $messageContent var';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Accounts<accounts#domain.com>' . "\r\n";
$headers .= 'Bcc: emailAddress1#domain.com,emailAddress2#domain.com,emailAddress3#domain.com,emailAddress4#domain.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
I got told a while back that there was a way that you could put your own email in the to field, but when the users receive the emails it looks like they were personally sent the email and the to field shows just their email.
Is this possible? Cant think how.
Thanks.
I'm struggling with sending my multipart email with plain text version as well as with HTML. Unfortunately when I receive it in Gmail it shows as downloadable message only as shown below:
The code is pasted below and although I went over like 100 questions here on SO I'm still stuck.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: donotreply#someaddress.com\r\n";
$headers .= "Subject: Test mail\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
// plain text version
$message .= $plainTextMessage;
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
// html version here
$message .= $htmlMessage;
$message .= "\r\n\r\n--" . $boundary . "--";
return #mail($to, $subject, $message, $headers);
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