PHP Email Not Work - php

i have a website wherein you can inquiry or leave questions and comments and send it via email, the code runs perfectly but it doesn't send email. here is my code:
$myemail = 'albertdaracan#gmail.com';//<-----Put Your email address here.
$fname = "albert";
$lname = "daracan";
$subject = "Magosaburo Inquery Form";
$email_address = $_POST['email'];
$message = "Name: ".$fname." ".$lname;
$message = "test";
$to = $myemail;
$email_subject = $subject;
$email_body = $message;
$headers = "From: $fname $lname <$email_address>\n";
$headers .= "Cc: ";
$headers .= "Reply-To: $email_address";
//redirect to the 'thank you' page
if(mail($to,$email_subject,$email_body,$headers)){
echo "mail successful send";
}else{
echo "Could not send you mail, Please try again later";
}
$message2 = "test";
$to2 = $email_address;
$email_subject2 = "Magosaburo";
$email_body2 = "$message2";
$headers2 = "From: Magosaburo <$myemail>\n";
$headers2 .= "Reply-To: $email_address";
//redirect to the 'thank you' page
if(mail($to2,$email_subject2,$email_body2,$headers2)){
echo "mail successful send";
}else{
echo "Could not send you mail, Please try again later";
}
my other works was fine it send email, but it is in other server...

why not try to fix this issue first
$fname = "albert" //missing semi colon
$lname = "daracan" //missing semi colon
$subject = "Magosaburo Inquery Form"; //terminated here
may be the values were not assigned well which causes the faultness

Related

how to hide reply-to header when received by mail box?

How can i hide reply to header , from mail boxes,
For example , i send a mail from test#domain.com with reply to as notification#domain.com, and receiver open the mail and click on reply, i want the receiver to see from email which is test#domain.com in reply, instead of reply to which is notification#domain.com, and also the reply will come notification#domain.com .
Any help. My code below
<?php
if(#isset($_POST['send'])){
$From = $_POST['From'];
$Subject = $_POST['Name'];
//$Message = $_POST['Message'];
$Message = "";
$Reply= "notification#domain.com";
$Emails = $_POST['Emails'];
$toname = $_POST['toname'];
$Name = $_POST['Name'];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
$headers .= "Reply-To: ".$Reply."\r\n";
$headers .= "From: ".$From."\r\n";
$headers .= "Hi<br>".$toname."\r\n";
$headers .= "<br><br>Are you today? <br><br><br><br>Thanks,<br>".$Name."<br><br>
Sent from my work office\r\n";
$Emails = explode("\r\n", $_POST['Emails']);
foreach($Emails as $email) {
mail($email,$Subject,$Message,$headers);
echo "<br>Sending Email from : name:".$Name.", email: ".$From.", to name: ".$toname.", email:".$email." => was successfully sent";
//echo "<br>Sending Email To : ".$email." => Done";
}
}
?>

Mail() - message body with utf-8 and html tags

Contact form on site use script below. It send 2 messages - to me and to the person filling in the form. In second mail I have problem with characters like "ąźćęś"....I would like to use utf-8. I set it in header, but it doesn't work. I need to use in message body html tags also.
What wrong in the code?
<?php
// Check for empty fields
if(empty($_POST['email']) ||
empty($_POST['phone']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$email_address = $_POST['email'];
$phone = $_POST['phone'];
// Create the email and send the message
$to = 'me#test.com';
$email_subject = "Mail to you";
$email_body = "Hello\n\n"."Test\n\nEmail: $email_address\n\nPhone: $phone";
$headers = "From: test#test.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
$to2 = "$email_address";
$email_subject2 = "=?UTF-8?B?".base64_encode("Thanks for you message")."?=";
$email_body2 = "Test mail ążźćęśó\n\nBest regards\nTester";
$headers2 .= "Content-Type: text/html; charset=UTF-8";
$headers2 = 'From: Tester <test#test.com>' . "\r\n";
mail($to2,$email_subject2,$email_body2,$headers2);
return true;
?>

want to send session values in url

hi i am taking values from a page and getting values in second page whihch is working correctly but i have to send the values in url
<?php
session_start();
$_SESSION["email_address"] = $_REQUEST["email_address"];
echo "Favorite color is " . $_SESSION["email_address"] . ".<br>";
//$errors = '';
$myemail = 'info#abcdef.com';//<-----Put Your email address here.
$to_go="abcdef#gmail.com";
$to = $to_go;
$email_subject = "Contact form submission: aaname";
$email_body = "You have received a new message. ".
" Here are the details: Kindly <a href='localhost/ci/email_wait.php?email_address='.echo $email_address.'&password'=.$password.'>
Click Here</a> to reset your password";
$headers = "From:". $myemail;
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
echo "Mail Sent. Thank you we will contact you shortly.";
?>
NOTE: This code will not work on localhost.
Check out PHP's documentation on string interpolation
You want something like:
$email = "something#somewhere.com";
$body = "Your email address is: $email, hooray!";
echo $body;
Which will output Your email address is: something#somewhere.com, hooray!
Why you echo $email_address and where you initialize your email_address proper way to do like this
$email_body = "You have received a new message. Here are the details: Kindly<a href='localhost/ci/email_wait.php?email_address='".$email_address."'&password='".$password."'>Click Here</a> to reset your password";
and you can also send mail from localhost through smtp settings and put headers also before mail like this
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

PHP reply-to error - need person's email, not admin

I have the below PHP contact form that has a CAPTCHA code to ensure is correct. However, when I reply to the email from the website it puts a random email which i believe is the server admin, however, I want it to be the persons email who sent the form in. below is the code, could you possibly be able to help me?
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty ($_SESSION['chapcha_code'] ) ) {
$youremail = 'info#example.com';
$fromsubject = 'www.example.co.uk';
$title = $_POST['title'];
$fname = $_POST['fname'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = $youremail;
$mailsubject = 'Message from Website'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is: '.$fname.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for your message. I will contact you shortly if needed.<br/>Go to <a href='/index.html'>Home Page</a>";
mail($to, $subject, $body);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
} else {
echo "You must write a message. </br> Please go to <a href='/contact.html'>Contact Page</a>";
}
?>
You'll need some headers so the from address is the users mail.
Also refer to the mail docs
try this
$headers = "From: $mail\r\n";
$headers .= "Reply-To: $mail\r\n";
mail($to, $subject,$body,$headers);

Warning: mail() [function.mail]: SMTP server response: 550 Invalid recipient:

I'm creating a 'forgot password' page where the user enters their email address and the script finds the password associated to that email, and sends it to the stored email address.
I believe the problem has to do with my SMTP Mailserver. I am using WAMP which doesn't have one so I downloaded one that was free.
This is the php script I'm using:
$id = checkEmail($email);
$record = readMemberRecord($id);
$password = #mysql_result($record,0,'cred');
if($password){
$email_subject = "Email Request";
$email_body = "Your password is ".$password.".";
$header = "NinjaMan";
mail($email, $email_subject, $email_body,$header);
$msg = "Your password has been sent to ".$email.".";
}else{
$msg = "Sorry, the email ".$email." wasn't found.";
}
The $msg outputs properly so I know the code is passing the mail function.
Try sending in a proper "From" in $header.
$emailFrom = "admin#yourdomain.com"; // match this to the domain you are sending email from
$email = "example#example.com";
$subject = "Email Request";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Your password is ".$password.".";
mail($email, $subject, $message, $headers);
See details of the mail() function.
If this doesn't work, try using PHPMailer. You configure it in code, no need to edit php.ini.
I've used it in some projects (v 2.0.4, I see the latest is 5.1) and had no problems.
Try using Google's server to send mails, you can see how to do that here
Try using this
//Email information
$to = "garggarima#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a test email message.";
$from = "support#sltechsoft.com";
$headers = "From:" . $from;
$mail=mail($to,$subject,$message,$headers);
if($mail) {
echo "Thanks for mail";
} else {
echo "Mail not Sent";
}
//Email response
echo "Thank you for contacting us!";

Categories