PHP Contact Form to Mail not working - php

Good day everyone, this is my first time to post here so pls bear with me. I need your help guys, I'm an artist that knows basic html5/css that's why i'm really not good in php.
Anyway I have a project that has a contact form, I just realized that yahoo mail is not working when I fill up the form online, but gmail's are good. Below is my php code. I've been following this PHP Mail() Contact-us form works fine if entering a Gmail sending address, but not with Yahoo but I really can't do it on my own! A brother needs your help. Thank you.
<?php
$field_name = $_POST['cf_name'];
$field_brand = $_POST['cf_brand'];
$field_category = $_POST['cf_category'];
$field_email = $_POST['cf_email'];
$field_facebook = $_POST['cf_facebook'];
$field_instagram = $_POST['cf_instagram'];
$field_number = $_POST['cf_number'];
$field_message = $_POST['cf_message'];
$mail_to = 'dulcetlifestylehub#gmail.com';
$subject = 'DULCET LIFESTYLE - BECOME FAMILY: '.$field_name;
$body_message = 'From Owner: '.$field_name."\n";
$body_message .= 'Brand Name: '.$field_brand."\n";
$body_message .= 'Brand Category: '.$field_category."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Facebook: '.$field_facebook."\n";
$body_message .= 'Instagram: '.$field_instagram."\n";
$body_message .= 'Number: '.$field_number."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'becomefamily.htm';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to dulcetlifestylehub#gmail.com');
window.location = 'becomefamily.htm';
</script>
<?php
}
?>

Related

Kurdish text not displaying properly in contact from

I made a simple contact form using HTML & PHP and I tested, it works perfectly, but when I wanna write in Kurdish or Arabic language the text not displaying properly in my email it looks like that: ÚÛبÛÙ
<?php
$field_name = $_POST['cf_name'];
$field_mobile = $_POST['cf_mobile'];
$field_service = $_POST['cf_service'];
$field_customer = $_POST['cf_customer'];
$field_message = $_POST['cf_message'];
$mail_to = 'email#email.co';
$subject = 'داواکاری بینینی بەڕێوەبەران';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'mobile: '.$field_mobile."\n";
$body_message .= 'Manager: '.$field_service."\n";
$body_message .= 'Sender: '.$field_customer."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Message send successfully :)');
window.location = 'https://#.co/interview';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Failed :( Please call the developer!');
window.location = 'https://#/interview';
</script>
<?php
}
?>
Please try below code:
mail( $mail_to, utf8_decode($subject), utf8_decode($body_message), utf8_decode($headers) );

contact_us.php isn't sending emails to my website associated mail address

I'm using this contact_us.php file to enable 'Contact us' section of my website. If i use my gmail or hotmail address here for $mail_to = 'user#gmail.com'; it works perfectly. But if i use my email address associated to the website i mean like $mail_to = 'user#mywebsite.com'; i'm not getting any mail to my inbox. I even checked my spam and all other folder. Can anyone please help me with this? How can i get emails to the email address associated with my website. Thanks in advance.
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'user#mywebsite.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to user#yahoo.com');
window.location = 'index.html';
</script>
<?php
}
?>
If you do not want to use mail function, than try SMTP mail from PHPmailer library.
You will be able to send email from your gmail or outlook or any other smtp account from your website. sharing you the link below:
https://github.com/PHPMailer/PHPMailer/tree/master/examples
Enjoy :)

Php form with radio value and queries message

<!-- PHP CONTACT FORM -->
<?php
$look = $_POST['look'];
$design = $_POST['design'];
$old_website = $_POST['old_website'];
$redesign = $_POST['redesign'];
?>
<?php
$field_name = $_POST['user_name'];
$field_email = $_POST['user_email'];
$field_message = $_POST['user_message'];
$mail_to = 'alzirabarretto#gmail.com';
$subject = 'Queries';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message.');
window.location = '/website_form.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to alzirabarretto#gmail.com');
window.location = '/website_form.html';
</script>
<?php
}
?>
I update the php code. When sending the mail it works fine but i don't understand when I didn't received my mail. I have change the radio value according what you have said. And what about the url which I create the input type? I'm bit little confused how to do in php code.
I think this line is wrong.
$radio = $_POST['look' , 'design', 'old_website' , 'redesign'];
Try capturing them separately like this,
$look = $_POST['look'];
$design = $_POST['design'];
$old_website = $_POST['old_website'];
$redesign = $_POST['redesign'];
And even for radio group LOOK, try changing the corresponding values. Or you will get value as radio_1,radio_2, ...

PHP Email validator (form) from brackets

I need help with the first $headers line.
I need the from to look like this:
name <email>
actually
$field_name <$field_email>
It should show from email in email client
Personname <person#emailaddress.com
How can I achieve this?
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$field_phone = $_POST['cf_phone'];
$mail_to = 'from#email.com';
$subject = 'Enquiry from Website, From: '.$field_name;
$body_message = 'Enquiry submitted to business, via website contact form.';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Telephone Number: '.$field_phone."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '$field_name' <'$field_email'>'"\n";
$headers .= 'Reply-To: '.$field_email.;
$mail_status = mail($mail_to, $subject, $body_message, $headers);
include 'contactendd.php';
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
window.location = 'thanks.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
window.location = 'thanksfailed.html';
</script>
<?php
}
?>
Thanks very much for your help
This line is the right idea:
$headers = 'From: '$field_name' <'$field_email'>'"\n";
but it should read
$headers = 'From: ' . $field_name . ' <' . $field_email . '>\n';
Just missed the periods to concatenate
Headers should be separated by CRLF "\r\n" -- not just \n.

My form keeps sending the information to my Junk email

I have a form on my page and the information I submit keeps going to my junk folder within my Hotmail email.
I'm not sure what to do I keep changing the headers but the mail still keeps coming into my junk folder.
The code for the PHP is:
<?php
$boundary = uniqid('np');
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'user#hotmail.co.uk';
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: PHP's mail() Function\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$headers .= "Subject: Contact\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
$message .= "This is the text/plain version.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
$message .= "This is the <b>text/html</b> version.";
$message .= "\r\n\r\n--" . $boundary . "--";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. I will contact you shortly.');
window.location = 'http://www.user.com';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to user#hotmail.co.uk');
window.location = 'url';
</script>
<?php
}
?>
One possible problem is if the smtp server from which you are sending the emails, doesn't match the "from" email.
For example if you fill the from field with "yourmail#gmail.com" and the smtp server is not the gmail's one, this might be marked as spam by some mail providers. Unfortunately, there is nothing you can do about it, besides from sending emails from your own domain, that resolves to your smtp server.

Categories