Simple send mail form using php (Not sending)

I am not receiving the email via our contact us form at the bottom of the page.

http://myshirtbuzz.com/2016

Any help would be appreciated.

Show us the code.

<form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
                                <div class="form-group">
                                    <input type="text" name="name" class="form-control" placeholder="Name" required>
                                </div>
                                <div class="form-group">
                                    <input type="email" name="email" class="form-control" placeholder="Email" required>
                                </div>
                                <div class="form-group">
                                    <input type="text" name="subject" class="form-control" placeholder="Subject" required>
                                </div>
                                <div class="form-group">
                                    <textarea name="message" class="form-control" rows="8" placeholder="Message" required></textarea>
                                </div>
                                <button type="submit" class="btn btn-primary">Send Message</button>
                            </form>
<?php
$name       = @trim(stripslashes($_POST['name'])); 
$from       = @trim(stripslashes($_POST['email'])); 
$subject    = @trim(stripslashes($_POST['subject'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to   		= 'orders@myshirtbuzz.com';//replace with your email

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

die;
?>
	// Contact form
	var form = $('#main-contact-form');
	form.submit(function(event){
		event.preventDefault();
		var form_status = $('<div class="form_status"></div>');
		$.ajax({
			url: $(this).attr('action'),
			beforeSend: function(){
				form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
			}
		}).done(function(data){
			form_status.html('<p class="text-success">Thank you for contacting us. We will contact you as soon as possible.</p>').delay(3000).fadeOut();
		});
	});

You say both “(Not sending)” and “I am not receiving the email” - do you know which?

Firstly, if you temporarily change the line
mail(…
to
echo mail(…
you will see a 1 if the message is sent, or 0 if it is not sent. That will narrow down where you should be looking.

If it is being sent, then it could well be marked as spam. Your code says
$headers = “From: {$name} <{$from}>”;
and you put in the email address of the person who fills out the form.

So if the form fillers email address is xxxx@gmail.com, many spam filters will do a quick check to see if your server IP belongs to gmail.com - and as it doesn’t, will assume that you are sending spam.

Change the From: line to contain an email address on your own domain. The email address doesn’t even have to exist, as long as spam checkers can see that the domain name part of the email address matches the IP of the domain name.

1 Like

Very much agree - I haven’t done much with sending mail for several years, but even back then the various servers I used would only allow you to send emails with a from-address that their server was configured to serve. As you’ve already got the Reply-to header in there, there’s no reason not to send it from a proper email like “web-response@mydomain.com” or something.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.