Link to home
Start Free TrialLog in
Avatar of terrysv1
terrysv1

asked on

PHP A HREF not calling function with onclick

Why does this link not call the function?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
      function sendmailer() {
      $to = "tmiller@practicevelocity.com";
      $headers = "From: GoUrgentCare.com <info@gourgentcare.com>\r\n".
                        "Reply-To: donotreply@gourgentcare.com\r\n".
                         "X-Mailer: PHP/" . phpversion();
      $subject = "ZipPass Setup Instructions";
      $body = "           
      1. Download
      2. Setup
      3. Create
      ";
      mail($to, $subject, $body, $headers);
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<a href="#" onclick="sendmailer()">Click here for instructions</a>
</body>
</html>
Avatar of Emad Gawai
Emad Gawai
Flag of United Arab Emirates image

you are calling php function on javascript onclick()
because you can't call a php function from your html file.
that function is not seen by the client, so it can't be called.
it's processed by the server.

fo this
<?php
      $to = "tmiller@practicevelocity.com";
      $headers = "From: GoUrgentCare.com <info@gourgentcare.com>\r\n".
                        "Reply-To: donotreply@gourgentcare.com\r\n".
                         "X-Mailer: PHP/" . phpversion();
      $subject = "ZipPass Setup Instructions";
      $body = "           
      1. Download
      2. Setup
      3. Create
      ";
      mail($to, $subject, $body, $headers);
      header("location:".$_SERVER['HTTP_REFERER']);
?>
into it's own file without the funtion.
sendmail.php

then from html file

<a href="sendmail.php">Click here for instructions</a>
on click is only to call javascript, or vbscript functions.
ASKER CERTIFIED SOLUTION
Avatar of Emad Gawai
Emad Gawai
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
2. form.htm

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<a href="submit.php">Click here for instructions</a>
</body>
</html>
if you don't have this line in your php
    header("location:".$_SERVER['HTTP_REFERER']);
after clicking the link, it will run the script and stay on that page. Blank.
Why did I not get an assist, since I said it first.
I said the same thing.