简体   繁体   中英

How do I add script to the mail send using phpmailer?

Mail Code in PHP:

$mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = 'Training Program';
    $mail->Body    = "<html><head><script type = "."text/javascript"." "."src = "."pgm_mgmt.js"."></script>Dear<b> ".$trainername[$i].","."</b>"."<br><br>I'd like to know if you can attend the "."<b>".$trainerpgmname."</b>"." held at "."<b>".$trainercompany."</b>"." on "."<b>".$trainerdate."</b>"."<br><br>You can either accept or reject the request by clicking the Accept or Reject buttons below <br>"."<button"." "."name = ".$trainerid[$i]." "."value = ".$accept." "."onclick = accept(".$trainerid[$i].")".">Accept</button>"."                    "."<button"." "."name = reject".$trainerid[$i]." "."value = ".$reject.">Reject</button>";
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

How should I add script file in this? And also how do I add "id" for the button and "onclick" for the accept and reject buttons? Please do let me know how can I pass the values to a external javascript file on click of the button in the mail

You can't. Well you can, but it won't work. I don't know of any email clients (including web clients like gmail) that allow running javascript in messages. Many also trash CSS, so you're really out of luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM