This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
So this is my code for sending an email. When I try to send an email i get right message, in this case "User Exist" and "Email is sent", but i can't receive an email. So can somebody find mistake and try to help me?
<form action="forgot2.php" method="post">
Enter you email ID: <input type="text" name="email">
<input type="submit" name="submit" value="Send">
</form>
error_reporting(0);
$email=$_POST["email"];
$Subject = "GOSPodin covek";
if($_POST['submit']=='Send')
{
mysql_connect('localhost','root','') or die(mysql_error);
mysql_select_db('login');
$query="select * from clanovi where email='$email'";
$result=mysql_query($query) or die(error);
if(mysql_num_rows($result))
{
echo "User exist";
}
else
{
echo "No user exist with this email id";
}
}
if(mysql_num_rows($result))
{
$code=rand(100,999);
$message="You activation link is: http://localhost/login_form/forgot.php? email=$email&code=$code";
mail($email, "Subject Goes Here", $message);
echo "Email sent";
}
else
{
echo "No user exist with this email id";
}
First of all, you need to check if the mail is actually sent:
if (mail($email, "Subject Goes Here", $message)) {
// then it's actually sent.
}
If mail() doesn't return false, then the mail was passed to your local mail server for delivery. Presume you already have a mail server set up on your local test box? If not, problem is obvious...
If PHP checks out OK and you still don't receive the mail (and it's not in your spam folders etc.), you need to investigate your server's mail logs for possible issues outside PHP.
...and for the love of code and all things sacred to debugging, do NOT use error_reporting(0); if you're actually trying to figure out what's wrong! (Error messages are kinda helpful for that.)
Are you sure your script is actually sending the mail?
Replace:
mail($email, "Subject Goes Here", $message);
echo "Email sent";
By:
if(#mail($email, "Subject Goes Here", $message)) {
echo "Email sent";
} else {
echo "Email not sent";
}
Assuming mail() does return true and that the email is a valid one, you want to make you have a valid smtp server configured in php.ini in the [mail function] section.
Just try
I use this works fine for me
$headers = 'From: support#example.com';
mail($payer_email, 'Tokens', "Thank you for purchase tokens $additional-message", $headers);
change this one.
$query="select * from clanovi where email='".$email."'";
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am trying to get a contact form using the built in mail function to work but I'm running into some problems.
What I would like:
On clicking 'submit' the form is sent to defined emailadres.php.
If sent successfully, a confirmation message is displayed.
If not sent, an error message is displayed.
What is currently happening:
Confirmation message already shows on page load; regardless of form submission.
Mail is not sent.
Code I'm using:
if ($_POST["submit"]) {
mail ($to, $subject, $body, $from);
$sendErr = "Your message has been sent";
} else {
$sendErr = "Your message could not be sent";
}
I'm fairly new to all this so any help figuring out where my thinking stalls would be appreciated. If I need to post more parts of the form I will.
The code you are using does not even check if the mail was sent successfully, it only checks it the formular was submitted. mail() returns true if the mail was sent successfully, false if not. So you can check its return value:
if ($_POST["submit"]) {
$sent = mail ($to, $subject, $body, $from);
// Check here if the mail was sent or not
if ($sent) {
$sendErr = "Your message has been sent";
} else {
$sendErr = "Your message could not be sent";
}
}
I'm having trouble making this properly work.
What I want to happen is for someone to be able to fill out the given information but there's an email validation which is just you put your email in Email: and is suppose to match in Verify Email: then in hopes that they did that write and if they answer the spam question right which is just "what is 5+5?" then the form will send to my email
The problem is that, although the email validation is working, the spam question even if you write the answer wrong, the form is still sent. I need it so that the spam and the email validation either or must be correct or the form won't send.
I hope made this simple for some to understand and help me out! Here's my PHP code. Let me know what I'm doing wrong.
<script>
<?php
$email1=$_POST['Email1'];
$email2=$_POST['Email2'];
$from=$_POST['Email1'];
$email="!YOUREMAIL#GOES.HERE!";
$subject="maintenance Request";
$message=$_POST['Box'];
$select=$_POST['Select'];
$name=$_POST['Name'];
$number=$_POST['Question'];
$message="Name: ".$name. "\r\n" ."\r\n" . "Email: " .$from ."\r\n" . "\r\n" . "Comment: " .$message ."\r\n" . "\r\n" . "Selected Machine: " .$select;
if($number==10) {
}
if(filter_var($email1, FILTER_VALIDATE_EMAIL)) {
}
if (filter_var($email2, FILTER_VALIDATE_EMAIL)) {
mail ($email, $subject, $message, "from:".$from);
echo 'Thanks You for the Maintenance Request! We will Contact you shortly. ';
}
else {
echo "This ($email2) email address is different from ($email1).\n";
}
?>
</script>
If the answer to the validation question is wrong, you should print a message and exit the script.
if ($number != 10) {
die("You are not a human!");
}
You're also never checking if the two emails are the same.
if(!filter_var($email1, FILTER_VALIDATE_EMAIL)) {
die("Invalid email ($email1)");
}
if ($email1 == $email2) {
mail ($email, $subject, $message, "from:".$from);
echo 'Thanks You for the Maintenance Request! We will Contact you shortly. ';
}
else {
echo "This ($email2) email address is different from ($email1).\n";
}
There's no need to call filter_var() on $email2. If it's equal to $email1 then it must be valid. If it's not equal to $email1, we don't care if it's valid.
This question already has answers here:
Why is my e-mail still being picked up as spam? Using mail() function
(5 answers)
Closed 9 years ago.
first time post. I did read through the site on this question but I didn't find the answer or didn't realize I found the answer. I'm putting a simple PHP email sign-up box on a web site. Here is my code:
enter code here
function spamcheck($field)
{
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
$recipient = "mymail#mydomain.com";
$subject = "Email subscription list";
$sender = $recipient;
$subscription = $_REQUEST['subscription'];
if (isset($_REQUEST['emaillist']))
$mailcheck = spamcheck($_REQUEST['emaillist']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{
$body .= "Email: ".$_REQUEST['emaillist']." \n";
$body .= "Subscribe: ".$_REQUEST['subscription']." \n";
if ($subscription == "subscribe")
{$location = "thankyou.html";}
else {$location = "thankyou2.html";};
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");
header( "Location: $location" ); } ?>
The emails go to the spam folder using either my gmail or an email on the site's domain. I think it's because the subject and recipient are the same, but it could simply be a matter of telling our site host to allow these mails through. Any help/suggestions are appreciated and thank you in advance.
$sender = $recipient;
Since you are sending an email to yourself, create a filter to prevent mails from yourself going into spam. Creating filters is explained here
Hi I was trying to send Email using php in xammp
I have already started Mercury Service
Heres my code
<?php
$to = "nikhil08514#gmail.com";
$subject = "Hi!";
$body="test";
$headers = "From: root#localhost.com";
if (mail($to, $subject, $body, $headers))
{
echo "Message successfully sent!";
}
else
{
echo "Message delivery failed...";
}
?>
when i execute code i am getting output as
Message successfully sent!
But when i check my mail box.I dont see mail.I checked all folders in my Mailbox but its not present
your code is right try that on server it will work surely, xampp does not send directly like that from xammp. by using smtp you can send.
I encounter a very strange problem with ixwebhosting.
I am able to send email using the php mail() function with $subject = "test";
But if $subject = "testing of information send"; then i won't be able to receive any email
But actually "Mail sent!" was displayed in the php page.
if (!mail($email, $subject, $body, $from)) { echo "Error Sending Email!"; }
else
{ echo "Mail sent!"; }
Is it possible that the email is being classed as spam somewhere down the track? Are you able to get logs from the mailserver indicating whether mail gets sent?