1, I tried to send e-mail in PHP to my Facebook group email, but these updates, doesn't appear. If I send the e-mail from my yahoo mail, it posted instantly. What kind of information should I add to the mail header?
2, Is is possible to add images as attachments?
My current mail sender code is:
<?php
$to = "mygroup#groups.facebook.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "me#yahoo.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Does the email need to come from "me#yahoo.com"? Because Yahoo mail uses SPF, which Facebook can use to verify that your email didn't actually come from there, and discard your email as a spoofing attempt.
If the email needs to come from me#yahoo.com, you'll need to connect to Yahoo mail through SMTP, and pass your username and password through, and legitimately send your email from there.
As for image attachments, it's possible.
EDIT: As per the lovely DaveRandom's comment, the following PHP packages should make your job MUCH easier: PHPMailer or SwiftMailer
Related
i am using php code to send emails to gmail or yahoo ids. i am using a 3rd party mail server to send my emails. my php code works and i can receive the content in my gmail inbox. but where do i save my sent emails ?? who gives me an inbox for all my received / sent emails. suggest me a Name ?
function helloEmail()
{
$from = new Email(null, "test#example.com");
$subject = "Hello World from the SendGrid PHP Library";
$to = new Email(null, "test#example.com");
$content = new Content("text/plain", "some text here");
$mail = new Mail($from, $subject, $to, $content);
$to = new Email(null, "test2#example.com");
$mail->personalization[0]->addTo($to);
//echo json_encode($mail, JSON_PRETTY_PRINT), "\n";
return $mail;
}
There is no inbox for your sent mails. You can send an e-mail using any e-mail address you choose, even if it belongs to someone else or doesn't exist.
For your received e-mail inbox, you'll have to make one yourself via any third party e-mail service such as Gmail or Hotmail, or via your web hosting platform using your own domain name if they provide e-mail services.
To save your sent e-mails you can opt to save them in a database.
I'm currently sending email messages such as password reset emails or confirmations and notifications from my website through PHP's mail() function.
I'm already specifying Return-path and Reply-to headers. I'm sending emails like this:
$to = "someone#gmail.com";
$subject = "Hello";
$body = "Blah blah blah";
$from = "rocketnuts#example.com";
$headers = "From: Rocketnuts <$from>\nReturn-path: $from\nReply-to: $from\n";
mail( $to, $subject, $body, $headers, "-f$from" );
This works fine, but to reduce the risk of these emails ending up in spam folders, I would like to send DKIM-signed emails.
Is this possible with PHP's mail() function, or should I use some 3rd party package? (which?)
When searching around, I see questions like "sending DKIM signed emails to Outlook.com" but I want a general solution, not something for specific recipient domains.
Just in case: I'm only sending emails from addresses # the actual domain where my PHP scripts are running, and I have access to its DNS records.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm using a basic script on a 1&1 hosted server:
$recipient = "email#domain.com";
$sender_name = $_POST['name'];
$sender_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html; charset=UTF-8"."\r\n";
$headers .= "From: {$sender_name} <{$sender_email}>"."\r\n";
$headers .= "Reply-to: {$sender_name} <{$sender_email}>"."\r\n";
mail($recipient, $subject, $message, $headers);
..but for some reason am not receiving any emails, nor any errors as per PHP mail() function not sending email instructs.
I thought this may be a server issue but 1&1 states that it is fully supported. I've also sent emails from this server/hosting before using just a recipient, subject and body and so I'm rather unsure as to why it is not working now!
UPDATE
Sending without headers, i.e.:
mail($recipient, $subject, $message);
..does work, so it would appear to be an issue with using the headers?
There may be many reasons, for example you should study what SPF is.
The $sender_email can't be any address, for example you can't put a gmail address and send emails claiming to be that sender, without any authentication, you aren't allowed to send email on behalf on that address, because I could for example send emails putting your address in the from, pretenting to be you when I'm not (I tried to use simple words)
You should use in the From something ending in #yourdomain.com, and set up SPF to allow your server's IP to send emails for that domain. OR otherwise send emails through SMTP (with PHPmailer, for example, it's very easy)
Errors in header does affect the mail delivery. if you send email with wrong headers, for example, let's say the email of the user is user#email.com and his name is "user user", and you send the email to user#email.com it might cause the email to go in spam or not accepted at all if it doesn't match on server.
Gmail, for one, has a name associated with every email id. if you put a wrong name with the email, there's a chance the email might not show up in inbox or sometimes even spams.
"But in the link I attached the example given uses a 'from' header set by a form input?"
if you want your users to be able to send email to you, best idea would be to use your own email address as the sender email. E.g. if your website is at website.com, configure an email like "contact#website.com" and configure your script to use this as From header, you can send it to your own email at the same domain(website.com) or any other email which you authorize. You can add the users's actual details in the mail. that'll ensure the successful delivery of the email always.
I've just updated a contact form to use PHPMailer to stop emails being marked as junk, with no luck.
It's a fairly straight forward setup I'm using but its still going into peoples junk mail.
Here is my script, I was wondering if anyone could tell what was wrong?
include_once('../inc/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$name = $_POST['name'];
$email = $_POST['email'];
$body = "Name: ".$name."\r\n";
$body .= "Email: ".$email."\r\n";
$body .= "Message: ".$_POST['message'];
$mail->From = "mailer#blah.com";
$mail->FromName = "Contact BLah";
$mail->Subject = "Contact From: Blah";
$mail->Body = $body;
$mail->AddAddress("john#blah.com", "john");
$mail->AddAddress("david#blah.com", "david");
if(!$mail->Send()) {
$errorMsg .= "Error sending message, please try again later.";
} else {
$errorMsg .= "Message Sent successfully.";
}
I thought that PHPmailer normally takes care of inserting proper headers?
Any thoughts?
EDIT: Added spam score
-Spam-Status: "score=0.0 tests=none version=3.1.7 cmae=v=1.0 c=1 a=8nJEP1OIZ-IA:10
a=soyWjZv28gkhNSke5wm04A==:17 a=fqdOs_Nl9wd82e3SDigA:9 a=l-lynuxnH-gfU2bevBoA:7
a=wPNLvfGTeEIA:10 a=nymK5Bb5l1cA:10 a=_6wjLm_vFSYA:10 xcat=Undefined/Undefined"
X-Spam-Level: *
EDIT 2: I just tried the script on a different server from the clients and it has the same result. Do I have to send through the SMTP setup for it not to be classed as spam?
Some reasons your mail can get marked spam:
You're sending spam
Your IP, or a block of IPs surrounding your IP has been marked as a spam source on one or more blackhole lists
The content of the email is triggering spam filters.
The recipient has added you to their blacklist
The recipient didn't add you to their whitelist
You're sending a mixed source mail ("From: xyz#example.com", but sending it from "someotherdomain.net")
SPF records for your server are misconfigured/not configured at all
Domain keys are misconfigured/not configured at all
etc...
PHPMailer is a tool. Consider it a hammer. The hammer may have bent the nail, but only because the wielder didn't aim right.
The only way you'll solve this problem is by examining the bounce messages (if any), and whatever showed up in the recipient's mailbox. If they receive the mail, but it goes into a spam folder, then get a copy of the mail and examine its headers. Most spam filters will put their spam score/reasoning in there.
Small hint:
add in a line like so
$mail->AddReplyTo( 'mailer#blah.com', 'Contact BLah' );
It should decrease your SPAM rating significantly.
I was having the same problem using PHPMailer, and here's what fixed the problem for me: set the Sender (this is different and distinct from the "From") to a valid email account for the domain you are sending the email from. This causes PHPMailer to properly set the "envelope-from" information so that the email passes SPF and Sender-ID validation. Without doing this, the "envelope-from" is a OS user id and server combination which will not be verifiable.
Example Code:
$mail = new PHPMailer;
$mail->From = 'from_email#domain.com';
$mail->Sender = 'sender_email#domain.com';
...
It is not necessarily PHPMailer's fault, there are several possible reasons for your server to be blacklisted. You can check here to see if this happened
I'm looking to create a form on my website where users can enter their email address and a message (however long). Then upon clicking on a submit button, the code, sends the message as an email to my mailbox.
I was wondering if someone knew what code i could use. I am using PHP as my server-side language.
You need to have access to an smtp server somewhere. Assuming you do, use the php mail function to send the mail like so:
$Name = "John doe"; //senders name
$email = "email#adress.com"; //senders e-mail adress
$recipient = "recipient#emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for receiver"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
mail($recipient, $subject, $mail_body, $header);
The smtp server is set in the php.ini file in these two lines:
SMTP = servername
smtp_port = 25
More information at w3schools site.
while the above two answers provide a basic email sending suggestion, there's one thing you should consider, the codes are not secure. spammers can inject Cc: codes and send spam using the form. if they do, your smtp provider may ban your account. try a dedicated mailer, like phpmailer
Try to use PHPForms. It is an ultimate web form builder that allows to create professionally looking email forms within just a few minutes. You will only need to create a PHP form by means of an intuitive interface and generate a code that can be easily copied and pasted to any web page.