how to call php function with parameters in href html tag -
i want call sendemail($email) function it's parameters in href tag when click on link page wrote in forbidden "you don't have permission access root folder on server"
<?php require 'phpmailer-master/phpmailerautoload.php'; function sendemail($email) { $mail = new phpmailer; $mail->issmtp(); $mail->host = 'smtp.gmail.com'; // specify main , backup smtp servers $mail->smtpauth = true; // enable smtp authentication $mail->username = 'zebalagp@gmail.com'; // smtp username $mail->password = '******'; // smtp password $mail->smtpsecure = 'tls'; $mail->port = 587; $mail->from = 'zebalagp@gmail.com'; $mail->fromname = 'ana grin emoticon'; $mail->addaddress($email); // add recipient $mail->ishtml(true); $mail->subject = 'blabla !'; $mail->body = 'salam,, <br> <b> participation grin emoticon especial grin emoticon '; $mail->altbody = 'this body in plain text non-html mail clients'; if (!$mail->send()) { echo 'no'; return false; } else { echo 'sent grin emoticon'; return true; } } $email='ayaradwan_93@yahoo.com'; //sendemail($email); $r=' <a href= ".<?php sendemail($email); ?>." > send email </a> '; echo $r; ?>
you're mixing server-side code , client-side code. run at different times in completely different contexts on (usually) completely different computers.
it's not clear code going do, it's executing sendemail()
function immediately when page requested. since you're not echoing result, a
tag looks this:
<a href="">send email</a>
two things:
- the email has been sent.
- an empty
href
try load current page or default directory listing or something. won't invoke server-side code.
what you're trying little more involved think. simplest approach, given have far, move of email functionality page. sendmail.php
. page have here link other one:
<a href="sendmail.php">send email</a>
when user clicks link, they'd invoke second page call sendemail()
internally , display result user. like:
<?php // define sendemail here sendemail(); ?> <p>the email has been sent. thank you!</p>
so request send email comes 1 page, action of sending on another.
you can make increasingly feature-rich in various ways:
- instead of link, use form posts values
sendemail.php
can use values when composing email. - instead of linking page, have button javascript code creates ajax request
sendemail.php
send mail without leaving current page. - etc.
but basic idea server-side code , client-side code can't interact directly. separated http requests. if client-side code wants invoke server-side functionality, needs make http request server-side resource (a "page" in case) performs action.
Comments
Post a Comment