Emails going to inbox but spam message are displaying - php

I'm trying to send email from my domain. Mail is delivering properly. But it showing some message mentioning that the delivered message is spam. Please help me to overcome that problem. This is the message I got Be careful with this message
This may be a spoofed message. The message claims to have been sent
from your account, but Gmail couldn’t verify the actual source. Avoid
clicking links or replying with sensitive information, unless you are
sure you actually sent this message. (No need to reset your password,
the real sender does not actually have access to your account!)
<?php
if(isset($_POST['submit'])) {
$email_to = "info#maxwell.com";
$email_subject = "Your email subject line";
$name = $_POST['name'];
$message = $_POST['message'];
$email_from = $_POST['mail'];
$email_message = "Form details below.\n\n";
$email_message .= "Name: ".$name."\n";
$email_message .= "Email: ".$email_from."\n";
$email_message .= "message: ".$message."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($email_to, $email_subject, $email_message, $headers)){
?>
<script>
window.location.href="contact.php?success";
</script>
<?php
// print("Thank you for contacting us. We will be in touch with you very soon.");
}
else{
?>
<script>
window.location.href="contact.php?fail";
</script>
<?php
}
// print("fail");
}
?>
<form method="post" >
<div class="form">
<div class="col-md-6 col-sm-12 col-xs-12 form-group">
<input type="text" class="form-control" name="name" placeholder="Your Name">
</div>
<div class="col-md-6 col-sm-12 col-xs-12 form-group">
<input type="email" class="form-control" name="mail" placeholder="E-mail Address">
</div>
<div class="col-xs-12 col-md-12 form-group">
<textarea name="message" placeholder="Message..."></textarea>
<!-- <input type="submit" value="SEND MESSAGE" class="btn-black bounce-top"> -->
</div>
<div class="col-xs-12 col-md-12 form-group">
<input type="submit" class="btn-black bounce-top" name="submit" value="SEND MESSAGE">
</div>
</div>
</form>

In order to avoid such situation. You can follow the following suggestions:
A Simple Implementation Example
<?php
mail("recipient#recipient.com", "Message", "A simple message.", "From: The Sender <sender#sender.com>");
?>
4 Ways To Make Your PHP mail() Emails Less Spammy
Use Headers
The Message Sender Domain and Server Domain Should Match
Be Sure to Properly Use the Content-type Attribute
Verify That Your Server Is Not Blacklisted
Detailed Explanation:
1. Use Headers
<?php
$headers .= "Reply-To: The Sender <sender#sender.com>\r\n";
$headers .= "Return-Path: The Sender <sender#sender.com>\r\n";
$headers .= "From: The Sender <senter#sender.com>\r\n";
?>
Be sure to replace the fourth parameter with the $headers variable as shown below.
<?php
mail("recipient#recipient.com", "Message", "A simple message.", $headers);
?>
2. The Message Sender Domain and Server Domain Should Match
Spammers are notorious for sending emails from one server and trying to make the recipient believe that it came from somewhere else. So if you are sending an email from example#example.com, it is a good idea the the script reside on example.com.
3. Be Sure to Properly Use the Content-type Attribute
The Content-type attribute enables a message sender to say whether or not an email is plain text or html, or whether it has attachments. Obviously, the easiest to use content type is text/plain. You just add your text as shown in the simple example, and you are done. But when you use the other content types, additional pieces might be expected. For example, with the text/html content type, an html body tag is expected. Not having this tag could result in your email being marked as spam.
4. Verify That Your Server Is Not Blacklisted
When a server is blacklisted, it means that that server has identified as one that has been sending a lot of spam. This results in recipient mail servers rejecting or filtering any mail that is received from that server.
So if your mail is not being received it is a good idea to verify that your server has not been blacklisted. This goes for both shared and dedicated servers. In a shared environment, it is common for other users on the server to be sending out spam. And in a dedicated environment, spammers may have found a way to exploit a vulnerability in a server or contact form to send out spam. So it is easy for either type of server to be blacklisted.

If you want a solution sure to not get marked as spam, look into Amazon's SES service. You will likely never exceed free tier pricing, and with a bit of configuration, you'll hit inboxes at much higher rates.

Related

PHP Submission Error [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I'm having a classic PHP form submission error. I tested the code earlier and it seemed to be working now when testing it again, the email never arrives.
This is the HTML (I changed the site/email address for security reasons of course)
<!-- Contact Form -->
<form method="post" action="http://example.net/assets/mail/mail.php">
<div class="row 50%">
<div class="6u 12u(mobile)"><input type="text" name="name" placeholder="Name" />
</div>
<div class="6u 12u(mobile)"><input type="email" name="email" placeholder="Email" />
</div>
</div>
<div class="row 50%">
<div class="12u"><textarea name="message" placeholder="Message" rows="6"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li>
<input type="submit" value="Send Message" />
</li>
</ul>
</div>
</div>
</form>
This is the PHP file:
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "es#example.net";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
The PHP file is located at the same place the HTML links to: http://example.net/assets/mail/mail.php and the email itself is working fine (use it daily). When I test the form out I get the echo/message saying thank you so is definitely finding the PHP file however, I simply don't get anything on my inbox.
Is such a simple code yet I'm really confused and unsure what is going on.
Any help is truly appreciate it.
The email could be blocked in the server's mail queue or blocked as spam by the email host. For linux based system, the email is usually logged in the /var/logs directory and there should be an equivalent on windows based servers. From here you should be able to see whether or not the server sends the email out into the world.
The code appears to be correct.
The real problem is the use of the mail function of php. If you look at the official documentation, you can see how it is necessary that the parameters passed to the function must meet special requirements.
In addition, there are some difference using email() with Windows or Linux.
My advice is to not use direct mail() but a library to send as PHPMailer https://github.com/PHPMailer/PHPMailer
Your code is right! It seems like a mail server problem. Try to change the recipient mail address and check if your server is in black list: http://mxtoolbox.com/blacklists.aspx

Email form (PHP; post - send and message on same page)

I have some issues regarding my contact form. I have tried several solutions and been reading Stack Overflow a lot... but as every code differs, I would need something unique for my solution. It should be quite simple though.
This is my "form page":
<form class="contact_form" action="send_form_email.php" method="post" name="contact_form">
<ul>
<li>
<label for="name">Namn:</label>
<input type="text" name="name" required />
</li>
<li>
<label for="email">E-post:</label>
<input type="text" name="email" required />
</li>
<li>
<label for="phone">Tfn:</label>
<input type="text" name="phone" required />
</li>
<li>
<label for="message">Meddelande:</label>
<textarea name="message" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" type="submit">Skicka</button>
</li>
</ul>
</form>
Today I am using a post function to post a "success message" on the same page. But I can not make it work with any solution tried. Validation is already built in CSS3. What I need is to send an email with the form (which have worked, but then the message and validation pops up on a new page) and a message to appear on the same page (This is not working, no matter what I try).
Help?
The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).
Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.
As such, the to parameter should not be an address in the form of "Something ". The mail command may not parse this properly while talking with the MTA.
Note:
It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.
For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.
Note:
The following RFCs may be useful: » RFC 1896, » RFC 2045, » RFC 2046, » RFC 2047, » RFC 2048, » RFC 2049, and » RFC 2822.
You can write clean PHP code while creating the headers correctly. First, build a list of all headers in an array. Then, glue them with "\r\n" character.
This code now looks clean and straight forward.
(Just compare it with your code )
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Sender Name <sender#domain.com>";
$headers[] = "Bcc: JJ Chong <bcc#domain2.com>";
$headers[] = "Reply-To: Recipient Name <receiver#domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $email, implode("\r\n", $headers));
?>
As noted in other, well, notes; the "additional headers" parameter can be easily exploited, when doing things like:
<?php
mail( $_POST['to'], $_POST['subject'], $_POST['message'], 'Reply-to: '.$_POST['from']."\r\n" );
?>
An easy way of fixing this, is removing CRLFs from the header-strings, like so:
<?php
$_POST['from'] = str_replace( "\r\n", '', $_POST['from'] );
?>
This way, the extra data will be part of the previous header.
There is also imap_mail used to send an email message.
This link will be much useful: http://php.net/manual/en/function.imap-mail.php
There's multiple solution for your problem depending on how you handle your post in PHP.
For pure PHP/HTML my solution would be,
In send_form_email.php set the message you want to display in session
Then, do a header location to the PHP page where you want to display the message
In this PHP check if the session variable is set and if it does, display it in HTML
It would look like that
send_form_email.php
if ( some_error )
$_SESSION['msg'] = 'Some error message';
else
$_SESSION['msg'] = 'Success !!';
header('Location: http://www.example.com/');
some_other_file.php
if (isset($_SESSION['msg']))
echo $_SESSION['msg']; // or add it to a variable for late use in your HTML
Another solution would be to sent the form using Ajax to your php file, then display the response from your file (the message) into a block in your HTLM page.

php mail function not sending email when From address is yahoo

Not sure if anyone else has experienced this but i have a simple form that sends out a email.
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="phone" id="phone" value="<?php echo $phone; ?>" />
<textarea name="message" rows="20" cols="20" id="message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
When submitted i have the following:
if ($_POST) {
$email_to = "myemail#yahoo.com";
$subject = "Contact Form";
$message = "Phone: {$phone}\r\nMessage: {$msg}";
$headers = "From: sendingemail#yahoo.com" . "\r\n";
mail($email_to,$subject,$message, $headers);
}
When the form is submitted the mail function returns true but no email gets sent however when i change the FROM email to anything else outside of yahoo such as something#gmail.com the email comes through. Anyone know how to solve this issue?
Yahoo marked your mail as spam and is probably just ignoring it.
This is probably true for hotmail as well.
Best thing todo is find yourself a good SMTP mail pluging/module (phpMailer for instance) and use the credentials of a legit mail account. This way you are sending mail trough a dedicated mail server and changes are you won't be marked as spam anymore.
Do notice however than when you sent loads of (simular) mails or your script gets hacked and is used for spamming, changes are that your legit mailserver becomes blacklisted or (if you are lucky) blocks your account as beeing unsafe.

PHP - e-mail being sent to junk on Hotmail

i'm trying to send e-mail using the function mail().
But my email is being sent to junk, and it works perfectly on gmail, what am i doing wrong?
<?php
if(isset($_POST['submit'])){
$name = $_POST["name"];
$name .= " ";
$from = $_POST['from'];
$subject = $_POST["subject"];
$message = $_POST["message"];;
$to = $_POST["to"];
mail($to, $subject, $message, "from: $name \n $from \n");
echo $name;
}
?>
<form method="POST">
<input type="text" placeholder="from" name="from" />
<input type="text" placeholder="to" name="to" />
<input type="text" placeholder="name" name="name" />
<input type="text" placeholder="Subject" name="subject" />
<textarea type="text" placeholder="Message" name="message"></textarea>
<input name="submit" type="submit" />
</form>
The problem could be that the domain name in your $from field doesn't match the server that the email is being sent from.
The IP address that you are sending from could also be on the spam blacklist for the email client provider you are using.
There are some other guidelines that can affect how email clients will detect your email as junk, such as whitespace in the header fields, missing Reply-To and Return-Path headers etc.
One of the reasons Hotmail moves your mail to spam, is because you let the user enter the 'from' address. If the domain from which the mail is sent doesn't coincide with the from address in the header, the mail is seen as spam. Some servers reject the mail altogether.
Using PHPMailer or SwiftMailer sure helps with setting the right headers, but you should never send mails from other domains than your own.
Another thing than using different php libraries, there is also the matter of whiletilsts/blacklists which are lists of domains/ips which mail hosting companies use to quickly distingquish spam from proper mail so they sometimes require you to send some kind of email from admin#domain... to the moderator to prove you're not a spam bot, try checking this for hotmail.
You might want to read: http://smallbusiness.chron.com/domain-whitelisted-hotmail-46827.html
use smtp for sending an email then it will not go in junk
http://www.mendoweb.be/blog/php-send-mail-smtp-server-authentication-required/

PHP emailing failing on WIMP

I've got a WordPress site with a contact form that works fine on my MAMP environment, but when I publish to my clients WIMP server I get a failure.
I am not at all familiar with WIMP environments- how does one go about checking PHP error logs
Offhand, are there issues with PHP emailing on WIMP that would be causing this?
Code:
<?php
if ($_POST["contact_name"]<>'') {
$ToEmail = 'me#domain.com';
$EmailSubject = 'New contact message';
$mailheader = "From: ".$_POST["contact_email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["contact_email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "<b>Name:</b> ".$_POST["contact_name"]."<br>";
$MESSAGE_BODY .= "<b>Email:</b> ".$_POST["contact_email"]."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
<h4>Your message was sent. We will be in touch with you shortly.</h4>
<?php
} else {
<form id="contact-form" name="contact" method="post" action="#">
<label for="contact-name">Name *</label>
<input type="text" id="contact-name" name="contact_name" tabindex="1" class="required"/>
<label for="contact-email">Email</label>
<input type="text" id="contact-email" name="contact_email" tabindex="2" class="email" />
<input type="submit" id="contact-submit" name="contact_submit" value="" tabindex="8" />
</form>
<?php
};
?>
Windows does not have a built in email server like unix type OSs tend to have. You need to configure php.ini to add SMTP server information through which to relay email.
The PHP manual page for the `mail()' function details a number of Windows-specific points. However, the main points which could affect you are in this section: (to quote)
The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).
Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.
As such, the to parameter should not be an address in the form of "Something <someone#example.com>". The mail command may not parse this properly while talking with the MTA.
There are a few other things to consider as well; please read the manual page for more.
Hope that helps.

Categories