I am trying to send an confirmation email after user makes an account. The email doesn't send anything. I did test it and the email is not even going to the spam or inbox folder. Am I missing something? Thank you for your help.
$status = "";
if (isset($_POST["sign_up"])) {
$first_name = (isset($_POST['first_name']) ? $_POST['first_name'] : null);
$last_name = (isset($_POST['last_name']) ? $_POST['last_name'] : null);
$username = (isset($_POST['username']) ? $_POST['username'] : null);
$password = (isset($_POST['password']) ? $_POST['password'] : null);
$email = (isset($_POST['email']) ? $_POST['email'] : null);
$phone = (isset($_POST['phone']) ? $_POST['phone'] : null);
if ($first_name == "" || $last_name == "" || $username == "" || $password == "" || $email == "" || $phone == "") {
$status = '<p style="color:#FF0000;">Please fill out all the field';
} else if (strlen($password) < 6) {
$status = '<p style="color:#FF0000;">Password must more than 6 characters';
} else{
$sql = "INSERT INTO members(
first_name,
last_name,
username,
password,
email,
phone
) VALUES (
'$first_name',
'$last_name',
'$username',
'$password',
'$email',
'$phone'
)";
$res = mysqli_query($mysqli,$sql) or die(mysqli_error());
if ($res) {
$to = $email;
$subject = "Confirmation from Yu Fong to $username";
$from = "abc#yahoo.com";
$message = "Please click the link below to verify and activate your account. \r\n";
$message .= "Testing";
$header = "From: " .$from. "\r\n";
$header .="Reply-To: ".$from. "\r\n";
$header .= "CC: abc#yahoo.com\r\n";
$header .= "Return-Path: ".$from. "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-Mailer: PHP". phpversion() ."\r\n";
$sentmail = mail($to, $subject, $message, $header);
if ($sentmail == true) {
echo $status = '<p style="color:#FF0000;">Congratulations! Your account has been created. An confirmation email has been sent!';
} else {
echo "Eror!";
}
}
}
}
I just tested your email form,it works perfectly,i got the email.
$to = "Myemail#derp.derp";
$subject = "Confirmation from Yu Fong to $username";
$from = "derpington";
$message = "Please click the link below to verify and activate your account. \r\n";
$message .= "Testing";
$header = "From: " .$from. "\r\n";
$header .="Reply-To: ".$from. "\r\n";
$header .= "CC: abc#yahoo.com\r\n";
$header .= "Return-Path: ".$from. "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-Mailer: PHP". phpversion() ."\r\n";
$sentmail = mail($to, $subject, $message, $header);
if ($sentmail == true) {
echo $status = '<p style="color:#FF0000;">Congratulations! Your account has been created. An confirmation email has been sent!';
} else {
echo "Eror!";
}
This is just your form,and it works so i am assuming the issue is coming from another place,try changing
if ($res) {
to
if (1+1 == 2) {
just to check if your If statement actually prints true,and go from there.
Try changing
if ($sentmail == true) { ...
to
if ($sentmail) { ...
Or to shorten it a bit try
if(#mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
Related
My PHP code for sending email its working good, but there is a problem that doesn't show who is the sender just show noreply#example.com. I hosted my website at ecowebhosting.
<?php
$error = "";
$successMessage = "";
if ($_POST) {
if (!$_POST["email"]) {
$error .= "An email address is required.<br>";
}
if (!$_POST["message"]) {
$error .= "The message field is required.<br>";
}
if (!$_POST["subject"]) {
$error .= "The subject is required.<br>";
}
if ($_POST['email'] && filter_var($_POST["email"], FILTER_VALIDATE_EMAIL) === false) {
$error .= "The email address is invalid.<br>";
}
if ($error != "") {
$error = '<div><p>There were error(s) in your form:</p>' . $error . '</div>';
} else {
$to = "example#gmail.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "MIME-VERSION: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = "From: ".$_POST['email'] . "\r\n";
$headers = "Reply-To: ".$_POST['email'] . "\r\n";
$headers = "Subject: ".$_POST['subject'] . "\r\n";
$headers = "Message : ".$_POST['message'] . "\r\n";
if (mail($to, $subject, $message, $headers)) {
echo $successMessage = '<div>Your message was sent, we\'ll get back to you ASAP!</div>';
} else {
echo $error = '<div><p><strong>Your message couldn\'t be sent - please try again later</div>';
}
}
}
?>
I want to add bcc in my mail function php file.
if(isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['message'])){
if(!empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['email']) && !empty($_POST['phone']) && !empty($_POST['message'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo'Please feel valid email';
}
else {
$to='kriti#vsbhotels.com, contact#vsbhotels.com, verun#vsbhotels.com';
$body = $fname."\n". $lname."\n" . $phone."\n" . $email."\n" . $message;
if(mail($to , $fname." ".$lname , $body ,'From: response#themerakihotel.com')) {
header('Location: thank-you.html');
exit();
}
else {
echo "Something went wrong!";
}
}
}
else {
echo 'Please Fill All Inputs';
}
}
else {
echo 'not okk';
}
echo "<meta http-equiv='refresh' content='0; url=http://merakihotels.in/demo/'>";
add in header:
$headers[] = 'Bcc: someone#example.com';
for your code:
mail($to , $fname." ".$lname , $body ,'From: response#themerakihotel.com' . "\r\n" . 'Bcc: someone#example.com')
Though not solved then try:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: FromName<from#example.com>' . "\r\n";
$headers .= 'BCC: Someone<someone#example.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Just add BCC:with your email id in headers parameter.
$headers="From: response#themerakihotel.com\r\n";
$headers.="BCC:WRITE HERE YOUR EMAIL ID";
mail($to , $fname." ".$lname , $body ,$headers);
I'm not versed in PHP and had this form built for me. It works 95% of the time, but sometimes the reply-to email will be johnsmith#hadrian.lunarpages.com
I'm reading up a similar issue on this page, but not exactly sure what to change in my form...
<?php
if (isset($_REQUEST['btnSubmit-group'])) {
$date = $_REQUEST['date'];
$time = $_REQUEST['time'];
$count = $_REQUEST['count'];
$name = $_REQUEST['name'];
$organization = $_REQUEST['organization'];
$email = $_REQUEST['email'];
$grouptype = $_REQUEST['grouptype'];
$phone = $_REQUEST['phone'];
$upgrademus = $_REQUEST['upgrademus'];
$upgradeowo = $_REQUEST['upgradeowo'];
$comments = $_REQUEST['comments'];
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
if ($count == "" || $name == "" || $email == "" || $phone == "") {
echo "All fields are required, please fill out again. ";
} else {
$to = 'info#example.com';
$subject = "Group Tour Inquiry from $name ($date, $count people)";
$from = $to;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = nl2br("Private Tour:<br>" .
"<b>Name:</b> $name\r\n" .
"<b>Email:</b> $email \r\n" .
"<b>Phone:</b> $phone \r\n" .
"<b>Organization:</b> $organization\r\n" .
"<b>Date:</b> $date\r\n" .
"<b>Time:</b> $Time\r\n" .
"<b>Count:</b> $count\r\n" .
"<b>Include:</b> $upgrademus\r\n" .
"<b>Include:</b> $upgradeowo\r\n" .
"<b>Comments:</b> $comments\r\n" .
"");
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $name<$email> \r\n";
$headers .= "Reply-To: $email \r\n";
if (mail($to, $subject, $body, $headers)) {
echo "<div class=\"thankyou\"></div><meta http-equiv='refresh' content='0;url=http://www.example.com/private-group-tours'>";
}
}
} else {} ?>
You're trying to send e-mail's to your self FROM the person whose entering this in, essentially attempting to spoof their email, and sometimes this will(should) get blocked. more can be read here - problem with php mail 'From' header
Change:
$headers .= "From: $name<$email> \r\n";
$headers .= "Reply-To: $email \r\n";
to
$from = 'Admin#mysite.com';
$headers .= "From: $from\r\n";
$headers .= "Reply-To: $from \r\n";
and then edit that static $from variable. Then take the users email out of the BODY of the email you receive, and send them an email.
i am not able to send email in php,Any one help me to identify
i am not able to send email in php,Any one help me to identify where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem.
i am not able to send email in php,Any one help me to identify where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem.
i am not able to send email in php,Any one help me to identify where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem. where i am wrong.After filling form All details has to go a specified email.but here it is displaying else condition.So,Please help me to solve this problem.
<?php
$englishname = $_REQUEST['firstname'].' '.$_REQUEST['lastname'];
$arabicname = $_REQUEST['firstnamearabic'].' '.$_REQUEST['lastnamearabic'];
$education = $_POST['education'];
$ar_education = $_POST['educationarabic'];
$email = $_POST['email'];
$country= $_POST['parent_cat'];
$city= $_POST['cit_cat'];
$area= $_POST['area'];
$mobilenumber= $_POST['mobileno'];
$doorno= $_POST['doorno'];
$phone= $_POST['phoneno'];
$street= $_POST['street'];
$apartment = $_POST['apartment'];
$experience = $_POST['experience'];
$postalcode = $_POST['postelcode'];
$landmark = $_POST['landmark'];
if(isset($_POST['requesttype'])&&$_POST['requesttype'] == 'addEmployee')
{
$to = 'arundsti#gmail.com';
$subject = 'NEW DOCTOR REGISTRATION DETAILS-FIND A DOCTOR';
$from = $_REQUEST['email'];
// mandatory headers for email message, change if you need something different in your setting.
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "CC: info#findadoctorsa.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "Name in English: $englishname.\r\n";
$message .= "Name in Arabic: $arabicname.\r\n";
$message .= "Education: $education \r\n";
$message .= "Education in Arabic: $ar_education \r\n";
$message .= "Email: $email \r\n";
$message .= "Country: $country \r\n";
$message .= "City: $city \r\n";
$message .= "Area: $area \r\n";
$message .= "Mobilenumber: $mobilenumber \r\n";
$message .= "DoorNumber: $doorno \r\n";
$message .= "PhoneNumber: $phone \r\n";
$message .= "Street: $street \r\n";
$message .= "Apartment: $apartment \r\n";
$message .= "Experience: $experience \r\n";
$message .= "Postalcode: $postalcode \r\n";
$message .= "Landmark: $landmark \r\n";
$sent = mail($to, $subject, $message, $headers);
if($sent){ ?>
<script>
alert('Your Details received Successfully...We will Touch with you shortly');
</script>
<?php
}
else {?>
<script>
alert('Sorry Problem in Submitting Details,Please try Again');
</script>
<?php
}
}
?>
I am trying on the following code but it keeps saying Mail not sent. How do I find the real issue? Code given below:
$full_name = htmlspecialchars(trim($_POST['full_name']));
$email = htmlspecialchars(trim($_POST['email']));
$phone = htmlspecialchars(trim($_POST['phone']));
$message = htmlspecialchars(trim($_POST['message']));
$to = "mail#example.com";
$subject = $full_name . ' is interested to have a business discussion with you';
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['email']) . "\r\n";
// $headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h3>Full Name: </h3>: ' . $full_name . '<br>';
$message .= '<h3>Phone: </h3>: ' . $phone . '<br>';
$message .= '<h3>Message: </h3>: ' . $message . '<br><br>=======================<br>';
$message .= '<h3>IP Address: </h3>: ' . $ip . '<br>';
$message .= '</body></html>';
if(mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo " Mail Not Sent";
}
Try this code hope this helpful.
<?php
//print_r($_POST);
//$fname = $_POST['fname'];
//$lname = $_POST['lname'];
//$email = $_POST['email'];
//$message = $_POST['message'];
if(isset($_POST['fname']) && $_POST['fname'] != ''){
$fname = $_POST['fname'];
}
if(isset($_POST['lname']) && $_POST['lname'] != ''){
$lname = $_POST['lname'];//phone number
}
if(isset($_POST['email']) && $_POST['email'] != ''){
$email = $_POST['email'];
}
if(isset($_POST['message']) && $_POST['message'] != ''){
$com = $_POST['message'];
}
$to = 'noreply#noreply.com';
$subject = 'Site Visiter.';
// message
$message = sprintf("Site visiter details: <br>Name:- %s <br> Phone:- %s <br> Email:- %s<br> Message:- %s",$fname,$lname,$email,$com);
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <nb158f#gmail.com>' . "\r\n";
$headers .= 'From: mysite.com <admin#site.com>' . "\r\n";
//$headers .= 'Cc: divakar.k#gmail.com' . "\r\n";
// Mail it
$flag = mail($to, $subject, $message, $headers);
echo '<script>alert("Mail Sent :");</script>';
echo '<script>window.location.href="index.php";</script>';