i am trying to echo an email address onto the next page 'send_email.php' through a link using the url.
The idea is that send_email.php sends out an email to the specific email address for which that link belongs.
i am currently getting undefined index 'contact_email' errors and i am not sure what i am doing wrong, i am trying to use $_GET as a means to retrieve the email address from the url and add this to the email to/recipient line in send_email.php
our link is on 'page1' where we use a mysql query to pull details from the database like so:
$myId2 = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
$query2 = mysql_query(" SELECT supplier_registration.contact_name,
supplier_registration.contact_email, supplier_registration.contact_number, supplier_registration.company_address, supplier_registration.company_postcode
FROM supplier_registration
INNER JOIN supplier_stats
ON supplier_registration.company_reg_number = supplier_stats.company_reg_number
WHERE supplier_stats.id = $myId2 AND supplier_stats.insurance_date = DATE(NOW())");
while($row2 = mysql_fetch_array( $query2 )) {
echo "<div class=\"contact_details\">Contact Details:<br/>";
echo "<p><font color=\"#999\">Contact Name:</font> ".$row2['contact_name']."<br/>";
echo "<font color=\"#999\">Contact Number:</font> ".$row2['contact_number']."<br/>";
echo "<p><font color=\"#999\">Contact Email:</font> ".$row2['contact_email']."<br/></p>";
echo "<p><font color=\"#999\">Postal Address:</font> ".$row2['company_address']."</br>";
echo "<font color=\"#999\">Contact Name:</font> ".$row2['company_postcode']."</p>";
echo "</div>";
echo "<a href=\"send_email.php?email=".$row2['contact_email']."\"\"><div class=\"buttons\">Send Reminder Email</div> </a>";
then when we click the link we go to send_email.php which looks like this:
<?php
$_GET['contact_email'];
$myEmail = $_GET['contact_email'];
$to = $myEmail;
$subject = "Hi!";
$body = "Hi,
How are you?";
if (mail($to, $subject, $body)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed…</p>");
}
?>
but i am getting these errors:
Notice: Undefined index: contact_email in C:\xampp\htdocs\hewden_spms\send_email.php on line 2
Notice: Undefined index: contact_email in C:\xampp\htdocs\hewden_spms\send_email.php on line 3
Email successfully sent!
can someone please show me where the problem is and how i can get this to work thanks
<a href="send_email.php?email="
your query string paramter name is email
not contact_email
It should be,
$_GET['email'];
$myEmail = $_GET['email'];
instead of
$_GET['contact_email'];
$myEmail = $_GET['contact_email'];
You are passing parameter through anchor tag with parameter as email
in
echo "<a href=\"send_email.php?email=".$row2['contact_email']."\"\"><div class=\"buttons\">Send Reminder Email</div> </a>";
^
and is trying to access like $_GET['contact_email'];
in send_email.php.
You have to use the parameter name you have used while passing, in the GET
. So change to $_GET['email'];
You are setting the $_GET parameter to be called 'email' in this line: <a href=\"send_email.php?email=".$row2['contact_email'].
use
echo "<a href=\"send_email.php?contact_email=".$row2['contact_email']."\"\"><div class=\"buttons\">Send Reminder Email</div> </a>";
instead of
echo "<a href=\"send_email.php?email=".$row2['contact_email']."\"\"><div class=\"buttons\">Send Reminder Email</div> </a>";
you are passing email=$row2['contact_email'] it means that your key is email and value is what comes in $row2['contact_email'], value could be anything but you can get value by key which is email.