• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8298
  • Last Modified:

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>
0
terrysv1
Asked:
terrysv1
  • 4
  • 3
1 Solution
 
GawaiCommented:
you are calling php function on javascript onclick()
0
 
nplibCommented:
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>
0
 
nplibCommented:
on click is only to call javascript, or vbscript functions.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GawaiCommented:
you need to create 2 pages
1- submit.php
<?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);

?>

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>

0
 
GawaiCommented:
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>
0
 
nplibCommented:
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.
0
 
nplibCommented:
Why did I not get an assist, since I said it first.
I said the same thing.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now