This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I am trying to create a 'contact me' form by sending data in HTML form to an email address using php mail() function.
I am using xampp and testing my code on localhost. I have installed Test Mail Server Tool and it is running on port 25.
Configuration of php.ini file
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = smtp.secureserver.net
; smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = zain.farid#live.com
HTML Code
<form action="upload.php" method="post" style="height:100%">
<input name="articleTitle" value="Title" maxlength="50"
id="articleTitle">
<textarea name="article-body">
Compose your article...
</textarea>
<script>
CKEDITOR.inline( 'article-body' );
</script>
<input name="senderName" type="text" value="Name" maxlength="50"
id="name" class="textBox">
<input name="senderEmail" value="Email address" maxlength="50"
id="email" class="textBox">
<input name="abtyou" value="About Yourself" maxlength="150"
id="abtyou" class="textBox">
<input type="submit" name="submit" class="button">
</form>
PHP Code
<?php
$thankYou="";
if(isset($_POST["submit"])) {
$recipient="zain.farid#live.com";
$subject="New Guest Post";
$sender=$_POST["senderName"];
$senderEmail=$_POST["senderEmail"];
$senderAbout=$_POST["abtyou"];
$message=$_POST["article-body"];
$title=$_POST["articleTitle"];
$mailBody="Name: $sender\nEmail: $senderEmail\nAbout Sender: $senderAbout\nTitle: $title\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="Thank you! Your post has been submitted.";
}
?>
No error is reported but i cant see any email in my inbox of the mentioned email address.
Can you please spot the error. I think its a configuration problem because i am using mail server for the first time and i think i might have made an error in configuration. Thank you
first check your spam box
and do notice that main mail services for preventing from spam and fake email reject this type of email ,for test , I think you should set valid mail server accounts like google yahoo and ...
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I'm fairly new to php and I'm still learning the basics. I created a simple "contact us" form that should send the data to an email address. However, I'm not receiving the email. The "Thank you" message displays correctly, but the email is never sent.
Unfortunately my knowledge in php is slim so I'm having difficulty trouble shooting this one. I did successfully code a simpler form with only one field. That one is sending correctly. Since this form has multiple fields, it seems to be throwing something off.
<?php
if($_POST["submit"]) {
$recipient="myemail#gmail.com";
$subject="Contact Form";
$sender=$_POST["sender"];
$senderEmail=$_POST["senderEmail"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";}
?>
<?=$thankYou ?>
<form method="post" action="company.php">
<input class="contact" type="text" name="sender"
placeholder="First Name" size="25">
<input class="contact" type="text" name="last"
placeholder="Last Name" size="25">
<input class="contact" type="text" name="title"
placeholder="Title" size="25">
<input class="contact" type="text" name="business"
placeholder="Business" size="25">
<input class="contact" type="email" name="senderEmail"
placeholder="Email" size="25">
<input class="contact" type="text" name="phone"
placeholder="phone" size="25">
<textarea class="contact" name="message"
placeholder="How can we help you?" rows="4" cols="56"></textarea>
<input class="blu-btn" type="submit" name="submit"
value="Send Message">
</form>
It's not throwing any errors, I'm just not receiving the email. I've checked spam, tried a separate email, I'm missing something. Thank you so much for your help!
You should check first if your server is truly sending the mail, changing your code a bit:
if($_POST["submit"])
{
$recipient="myemail#gmail.com";
$subject="Contact Form";
$sender=$_POST["sender"];
$senderEmail=$_POST["senderEmail"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\n\n$message";
if (mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>"))
{
echo "<p>Thank you! Your message has been sent.</p>";
}
else
{
print_r(error_get_last()["message"]);
}
}
Take a look into the PHP Documentation for mail() function
Return Values
Returns TRUE if the mail was successfully accepted for
delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for
delivery, it does NOT mean the mail will actually reach the intended
destination.
Probably the server itself isn't properly configured to send email.
Is a shared hosting? Or something like?
Kind regards!
The environment where you run this makes all the difference. Mail may not be configured correctly or, some spam filter blocked it. In this case, nothing in your code can make a difference.
If you have control of the server, and you know how, you could check the mail program. If you are limited to only writing code, you have other options. You can use SMTP and send email through an external service. Then you can use mailtrap.io to capture the outbound email. This is a good way to go for debugging and making sure that your code is right.
You can use SwiftMailer if you want to try an alternative mail client.
This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 4 years ago.
I have set up a contact form which is to send email to anyone from WordPress page. It's sending email but all are going to SPAM folder. How to prevent it to go to Spam folder but go to Inbox?
however, I gave it try from another wordpress site, all emails going to inbox perfectly, and I've found a difference that is all email going to inbox has one extra line in details that is-
mailed-by: p6plcpnl0235.prod.phx3.secureserver.net
But the emails going to the SPAM folder doesn't have this above line, Is it can be a cause? If so how to enable this secureserver.net
Can anyone please help me?
Here is what I am using in page-
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "admin#mail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($email, $subject, $comment, "From:" .$admin_email);
//Email response
header('Location: /email-sent');
}
//if "email" variable is not filled out, display the form
else {
?>
<div class="container send-email-form-wrapper">
<div class="row">
<div class="send-email-form">
<form method="post">
<li> Email: <input name="email" type="text" /> </li>
<li> Subject: <input name="subject" type="text" /></li>
<li> Message: <textarea name="comment" rows="5"></textarea></li>
<li><input type="submit" value="Submit" /></li>
</form>
</div>
</div>
</div>
<?php
}
?>
This is more about your hosters internal sendmail mail setup that is used by the mail() function. If possible, try to use an tested SMTP mailer like Swiftmailer or PHPMailer instead. That way you could work around the sendmail smarthost configuration issue.
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.
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/
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.