Presentation is loading. Please wait.

Presentation is loading. Please wait.

>> PHP: JS Integration & Emails. function validate() { } Inserting / Uploading Items to DB Web-Based Systems - Misbhauddin <?php ?> type=“submit” 2 1.

Similar presentations


Presentation on theme: ">> PHP: JS Integration & Emails. function validate() { } Inserting / Uploading Items to DB Web-Based Systems - Misbhauddin <?php ?> type=“submit” 2 1."— Presentation transcript:

1 >> PHP: JS Integration & Emails

2 function validate() { } Inserting / Uploading Items to DB Web-Based Systems - Misbhauddin <?php ?> type=“submit” 2 1

3 1. Using the submit() in JS Steps – After successful validation in JavaScript, call the submit function Web-Based Systems - Misbhauddin 3 document.form-name.submit();

4 2. Using the onsubmit() attribute in form Steps – Include the onsubmit attribute in the form tag – In javaScript validation, return 'true' if everything's fine, or 'false' if not. Returning 'true' means continue with the submit process and send data over to the php code. Web-Based Systems - Misbhauddin 4

5 3. Using Ajax AJAX = Asynchronous JavaScript and XML. – Allows web pages to be updated asynchronous – Possible to update parts of a web page, without reloading the whole page Web-Based Systems - Misbhauddin 5 $(document).ready(function() { $("#login_form").submit(function() { $.post("login_verify.php",{userid:$('#userid').val(),password:$('#password').val()},function(data) { if(data=='yes') //if correct login detail { document.location='clientprofile.php'; } else { } ); }); Sample

6 EMAILS IN PHP PHPMailer

7 Using a Third-Party Library PHPMailer – Probably the world's most popular code for sending email from PHP! – Integrated SMTP support Download – https://github.com/Synchro/PHPMailer https://github.com/Synchro/PHPMailer Web-Based Systems - Misbhauddin 7

8 Including PHPMailer Use the require_once() command – include() – [suppresses warnings if file does not exists] – require() – [warns if file does not exist] – require_once() – [similar to require but loads file once] The file of concern – class.phpmailer.php – class.smtp.php Web-Based Systems - Misbhauddin 8

9 Using PHPMailer Prerequisite Knowledge – PHPMailer uses Object-Oriented in PHP Steps – 1. Create a new Object $mail = new PHPMailer(); – 2. Access function for the newly created object using ‘->’ For example: $mail->ValidateAddress($email); Web-Based Systems - Misbhauddin 9

10 Using PHPMailer – To/From $mail->From = 'from@example.com'; $mail->FromName = 'Mailer'; Add a recipient - Name is optional $mail->AddAddress('josh@example.net', 'Josh Adams'); $mail->AddReplyTo('info@example.com', 'Information'); $mail->AddCC('cc@example.com'); $mail->AddBCC('bcc@example.com'); Web-Based Systems - Misbhauddin 10

11 Using PHPMailer – Subject & Body $mail->Subject = 'Here is the subject'; $mail->Body = $message; If message is HTML $mail->IsHTML(true); // Set email format to HTML $mail->MsgHTML($message); $mail->AltBody = 'This is the body in plain text for non- HTML mail clients'; Adding Attachments $mail->AddAttachment('/var/tmp/vcard.info'); Web-Based Systems - Misbhauddin 11

12 Using PHPMailer – Confirmation if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: '. $mail->ErrorInfo; exit; } echo 'Message has been sent'; Web-Based Systems - Misbhauddin 12

13 SMTP Server PHPMailer has its own SMTP Server which may not work on localhost but will work once deployed on a server Other options – Use a custom SMTP Server (Gmail) – Steps: Define Your Username & Passowrd – define('GUSER', 'you@gmail.com'); // GMail username – define('GPWD', 'password'); // GMail password Functions – $mail->IsSMTP(); // enable SMTP – $mail->SMTPAuth = true; // authentication enabled – $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail – $mail->Host = 'smtp.gmail.com'; – $mail->Port = 465; – $mail->Username = GUSER; – $mail->Password = GPWD; Web-Based Systems - Misbhauddin 13

14 Web-Based Systems - Misbhauddin 14 Issue with using Gmail Address


Download ppt ">> PHP: JS Integration & Emails. function validate() { } Inserting / Uploading Items to DB Web-Based Systems - Misbhauddin <?php ?> type=“submit” 2 1."

Similar presentations


Ads by Google