I have made a new website for learning web development and I was taught to use the php mail function to send emails. When I use the following code in the headers to send an email to my gmail address:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <admin#myWebsite.com>' . "\r\n";
I noticed that the email has a question mark next to it and gmail says: "Gmail couldn't verify that myWebsite.com actually sent this message (and not a spammer)." Is there any way to prevent this from happening?
As for my second question; I noticed that when I changed the last line of the header to:
$headers .= 'From: <admin#someOtherWebsite.com>' . "\r\n";
The email still gets sent like it came from another person's domain. (Although with the same warning mentioned above). But if the header is changed to:
$headers .= 'From: <admin#gmail.com>' . "\r\n";
Then no email is sent. So can someone tell me what is google doing to prevent others from using php mail to send fraudulent emails using their domain?
Your mail server isn't configured as tight as it could be.
You should make sure that SPF records are set for your domain, that you have proper Reverse DNS for the name your mail server uses in its HELO statement, and set up and use SSL for SMTP (ESMTP), easy to do with a letsencrypt cert.
Related
We are sending about 1 lac email daily using sendgrid API.
But what happen is thousand of mail are undelievered to the recipient.
we want to get the list of these undelievered mail. How is that possible ?
Please suggest some idea or links. becouse I am lost and would really appreciate the assistance.
Thank you.
wow..! finally i made it...
curl code-
curl -X GET
https://sendgrid.com/api/bounces.get.json?api_user=undefined&api_key=XXXXXXXX
and here is my the php code
$ch =curl_init('https://sendgrid.com/api/bounces.get.jsonapi_user=10timeslocal&api_key=10timeslocal');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
Thanks a lot to everyone tried to solve this.
I'd start with reading the API docs for bounces, blocks, invalid emails, and spam reports.
You can also consume SendGrid's Event Webhook which will send you post requests with the information you are looking for.
have a table in the database, that must contains the log of all emails send to users. then later fetch status of these emails via sendgrid apis. then update their status as success, bounce, invalid.
then for next time don't send emails to that persons whose status in your list are bounce or invalid.
this way you can avoid sending emails to bounces or invalid users.
My work requires an authorization for internet use. I log in, and after that it recognizes me and lets me access whatever I need.
I have been using POSTMAN to test send to and receive from a company RESTful service. It automatically uses my same internet use auth at the other end to give my user account POST and GET permissions.
Now, I am trying to automate with a perl script and it won't authorize. The owner of the RESTful service says if I make a windows/.net application it will authorize automatically, but that isn't an option.
Any suggestions? I would think I could just do special headers or something and duplicate whatever windows is doing....
I have been asked to provide what I have done so far
#!/usr/local/bin/perl
use strict;
use LWP::UserAgent;
my $ua=LWP::UserAgent->new;
my $server_endpoint = "The post destination";
my $req= HTTP::Request->new(POST => $server_endpoint);
$req->header('content-type' => 'application/json');
my $post_data="[ SOME JSON HERE ]";
$req->content($post_data);
my $resp = $ua->request($req);
if($resp->is_success){
my $message = $resp->decoded_content;
print "received reply : $message\n";
}
else{
print "post error code : ",$resp->code,"\n";
print "post error message : ",$resp->message,"\n";
}
In the past when I had to authenticate against an IIS server I had to use LWP::Authen::Ntlm to get it to authenticate.
For more information about LWP::Authen::Ntlm, see https://metacpan.org/pod/LWP::Authen::Ntlm
The main "pitfalls" I had is that keepalive is required, and that newer versions of IIS now use Digest, and not NTLM
In those cases, I simply switched to the built-in LWP::Authen::Digest (it comes inside LWP)
Have a look at a similar question (scroll up to the top see the question) and see if the included bit of Perl code doesn't help...
LWP::UserAgent HTTP Basic Authentication
The short version is that it doesn't appear that your Perl code above includes any login information and this POSTMAN plugin may be sending over cached login info that your Perl code is not yet aware of.
I have a simple Contact form, with 'Send' button', that send mail from an email to an email.
In the local host with wamp server i have done it and it's working.
I have used 'fake email program' to send it, I entered the from email in the 'sendmail.ini' file.
How can i achieve the same goal using plesk service as a server, where can I enter the from email address?
It sounds like a simple task but I have just spent over an hour looking for it.
i have an contact.html form with php for serer code, what i am trying to do is to send the contact.html form details that the user has filled to an external email, In local host i managed to do it but know when i uploaded to server I am having trouble to locate the 'from email address field' (where i can setup the email address to emails that are going out from the site).
Suppose you own a site and some user fill the 'contact us' form, You as the site owner will receive an email from your site with the user details that the user filled in the contact form.
This code is from my php file #mail($email_to, $email_subject, $email_message, $headers);
and by using 'wamp server' on 'my local computer' and external fake email sender program,
I filled up this file with my 'email from address' (sendmail.ini) with this lines:
'smtp_server=smtp.gmail.com', 'smtp_port=25' and 'authentication' details: username= my_name#gmail.com And password='mypassword' for that email.
This is what i am looking for in 'plesk' server desk The location of that ini file where i can enter the from address, smtp_port and authentication details.
This is how I do it with PHP and the Mail() function:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit' . "\r\n";
$headers .= 'From: MyName <' . $from . '>' . "\r\n";
mail($to, $subject, $html, $headers);
$from = from email
$to = to email
$html = email body
$subject = email subject
Im sending out an order conformation for recipients via the simple mail function built into PHP, and this works fine. It's a "nice" email set up in tables and a few styles with the details in it
However a few of the recipients just see html tags, and of course can't understand anything..
If i get one, it shows perfectly in thunderbird, hotmail, gmail..
The html is perfect, not missing any end tags, and i send some headers also as i have read i should. this is my mail send function:
$body = "some html tags, set up in a table" ;
$sendto = "The recipients email here" ;
$subject = "subject here" ;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "To: theemailhere <theemailhere>\r\n";
$headers .= 'From: <thefromemailhere>' . "\r\n";
mail($sendto, $subject, $body, $headers);
Is this an error from my side, or has the recipient chosen not to receive html emails? I mean is this still possible in 2012 and do people disable this??
And if so, what could be a good workaround to do this. I mean i would like to avoid using plain text.
Yes. There are really email clients which do not allow HTML emails. I guess older Outlooks are one of these, too, but not sure.
So, anyway, it is not your fault, it is the user's. See Source 1 and Source 2.
And you can never be sure what does the user's mail program accept. Only plaintext is surely accepted. Quoting Source 2:
"The best you can do is anticipate how each of the major clients will
break your design, and then try to control how it breaks, so that it’s
still readable by most of your recipients."
It can be solved only with multipart messages, but then some people will get plaintext. See Source 3 for some details on the issue and Source 4 for solutions.
Some documents on this: Source 1, Source 2, Source 3, Source 4
I've been using Zend_Mail recently (from ZF), which has the option to set a plain text message, and then a HTML message which overrides it where HTML is available. I'm unsure of how this is implemented in the message (headers/etc.) but this could be an answer to your problems.
I have this:
open(MAIL,"|/usr/sbin/sendmail -t");
## Mail Header
print MAIL "To: $GLOB_OPT{email}\n";
print MAIL "From: $GLOB_OPT{from}\n";
print MAIL "Subject: $GLOB_OPT{sub}\n";
print MAIL qq|Content-Type: text/html; charset=us-ascii\n|;
print MAIL qq|Content-Transfer-Encoding: 7bit\n|;
print MAIL qq|MIME-Version: 1.0\n\n|;
print MAIL qq|<h3>Download File :</h3><br>|;
print MAIL qq|Click Here|;
close(MAIL);
I want to send the hyperlink to user so they can download the csv file in the $GLOB_OPT{html} path.
When I open the link in my email, it opens the csv in the browser. I want instead the browser to download the file. What can i do?
Try using content-disposition in http headers on the webserver's side. This even works with .htaccess.
As far as I understand, the way you send the e-mail has little to do with the save/display choice in the browser.
Don't use the system sendmail command. Instead use the MIME::Lite module.
They have a coding example that pretty much does exactly what you want to do.
This way, you're not depending upon an external command that may or may not work (depending upon the system and its configuration).
You could output the CSV via a script which sends to the browser first mime-header "application/octet-stream" instead of the default
MIME type sent by apache(or the used server). You can also configure the server to send the header it self by associating the .csv extension with "application/octet-stream" mime type.
see also The apache docs