Hi...tried to send email notification in php but not successful. When i check my email there is no email notification received. Below is the coding. Once the user click notify button, an email notification supposed to be sent to responsible person...Please advise...Thanks a lot.

<?php
error_reporting(E_ALL ^ E_NOTICE);
 $_SESSION['Targetid'];
 $_SESSION["Progressid"];
$conn = mysql_connect("mysql","pqa","pq");
mysql_select_db("pqad",$conn);

if(count($_POST)>0) {

mysql_query("UPDATE progress set Quanprogress4='" . $_POST["Quanprogress4"] . "', Qualprogress4='" . $_POST["Qualprogress4"] . "' WHERE Targetid='" . $_SESSION["Targetid"] . "' and Progressid='" . $_SESSION["Progressid"] . "'");
$message = "Record Modified Successfully";
}

$result = mysql_query("SELECT * FROM progress WHERE Progressid='" . $_SESSION["Progressid"] . "'");
$row= mysql_fetch_array($result);
?>
<html>
<head>
<title>Add New User</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="frmUser" method="post" action="">
<div style="width:500px;">
<div class="message"><?php if(isset($message)) { echo $message; } ?></div>
<div align="right" style="padding-bottom:5px;"><a href="list_progress4.php" class="link"><img alt='List' title='List' src='images/list.png' width='15px' height='15px'/> List Progress</a></div>
<p><b>1.Target</b></p>
a.i.Quantitative Progress (e.g. average,numerical,%,sum): <input type="hidden" name="Progressid" class="txtField" value="<?php echo $row['Progressid']; ?>"><input type="text" name="Quanprogress4" class="txtField" value="<?php echo $row['Quanprogress4']; ?>"><br>
a.ii.Qualitative Progress: <input type="text" name="Qualprogress4" class="txtField" value="<?php echo $row['Qualprogress4']; ?>"><br> 
<input type="hidden" name="Targetid" ><br> 
<td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
</div>
</form>
</body></html>
<p><b>3.Improvement Plan</b></p>

Team Leader:<input type="text" name="Pic" value="<?php echo $_SESSION["Username"];?>" ><br>


<?php
$con = mysql_connect("mysql","pqa","pq");
if (!$con)


    {


die('Could not connect: ' . mysql_error());


    }


mysql_select_db("pqad", $con);
$sql="select * from improvement_plan";
$myData=mysql_query($sql,$con);
echo "<table border=1>
<tr>

<th>Responsible</th>;
<th>Notify</th>;
</tr>";


    while ($record=mysql_fetch_array($myData)){


echo "<tr>";
echo "<td>" . $record['Responsible4'] . "</td>";
echo"<td>" . $record['Notify4'] . "</td>";
echo "</tr>";


    }


echo "</table>";
mysql_close($con);
?>

<form action="" method="post">


        <input type="submit" value="Notify" />


    <input type="hidden" name="Notify4" value="Notify" />
</form>
<?php



    }


echo 'Message has been sent'; */
?>
<?php
$email=$_POST['email'];
$name=$_POST['name'];
$subject = "New Mailing List Signup";
$sendto = "email@domain.com";
$body = "This is the information filled out for their signup. /n /n Name: $name /n Email: $email /n /n This signup was generated by your server.";
mail($sendto,$subject,$message);
?>
 </div>
</div>
</div>
</form> 
<?php


    //}


?>
</body>
</html> 
<?php include('ipdfooter.php');?>

Dani AI

Generated

Quick summary and likely cause (references to the thread): confirmed testing on localhost and asked the right question; ’s spot-on comment about a missing SMTP/MTA on XAMPP is the usual culprit. PHP’s built-in mail() hands messages to a local mail transfer agent (on *nix that is usually sendmail/postfix; on Windows it uses the SMTP settings in php.ini) and only reports whether the message was accepted for delivery by the MTA — it does not guarantee end-to-end delivery. (php.net)

Practical troubleshooting checklist (do these in order):

  1. Add explicit error reporting and check the boolean return value from mail() and any warnings in PHP/Apache logs.
  2. Ensure a From: header is present (either via additional_headers or sendmail_from in php.ini) — missing From often causes PHP warnings.
  3. On Windows/XAMPP set SMTP, smtp_port and sendmail_from in php.ini and restart Apache; on Linux set sendmail_path or install/configure an MTA (Postfix/Exim) or use a sendmail replacement.
  4. For development use an SMTP-catcher (MailHog, Papercut, etc.) so messages can be observed locally instead of being routed to the Internet.
  5. For production or reliable sending, prefer an SMTP library (PHPMailer, Symfony Mailer) + authenticated SMTP relay instead of raw mail(). (php.net)

If switching to SMTP code (recommended): a minimal PHPMailer flow — configure host, auth, username/password, set From, add recipient, then call send() and inspect ErrorInfo on failure. This avoids platform differences and gives useful debug output.

use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';

$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'user@example.com';
$mail->Password = 'secret';
$mail->setFrom('from@example.com','Sender');
$mail->addAddress('recipient@domain.com');
$mail->Subject = 'Notify';
$mail->Body = 'Message body';
$mail->send();

For closure: ’s advice to test on a live server or configure a local SMTP catcher is solid, and ’s suggestion to use a test-mail tool points in the same direction. If problems persist, capture the exact PHP warnings and the webserver/MTA logs (enable mail.log in php.ini) and try PHPMailer’s SMTP debug output — that information pinpoints whether the issue is configuration, authentication, or network. (php.net)

Recommended Answers

All 4 Replies

The code seems fine to me.

Just a quick question - are you testing it on an already live website or are you testing it via your localhost?

Hi...am testing it on localhost...Thanks.

I had this problem when testing on localhost once...

The thing was, is that my xampp server didn't have a functioning mail server (SMTP). Unfortunately, you need to upload your script to a functioning server with SMTP installed/working (if I were you I'd just create a test/ directory on your webserver).

I believe it's possible to get SMTP working on XAMPP using this and theres a ZIP download to try out. I've never used this though so haave no idea how good it is.

In a nutshell: create a test/ directory on your webserver and test your scipt there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.