SMTP Configuration and Send the mail using PhpMailer & Gmail

PHPMailer is a standout amongst the most well-known open source PHP libraries to send messages. In this article, we will discuss why you should utilize PHPMailer rather than PHP’s mail() capacity and we’ll demonstrate to some code tests on generally accepted methods to utilize this library. Much of the time, it’s a contrasting option to PHP’s mail() work, however, there are numerous different situations where the mail() capacity is basically not sufficiently adaptable to accomplish what you require.

Most importantly, PHPMailer gives a protest arranged interface, while mail() is not question situated. PHP developers, for the most part, prefer not to make $headers strings while sending messages utilizing the mail() work since they require a great deal of getting away – PHPMailer makes this a breeze. Developers likewise need to write grimy code (getting away characters, encoding and designing) to send attachments and HTML-based messages when utilizing the mail() work though PHPMailer makes this easy.

Additionally, the mail() work requires a local mail server to convey messages. PHPMailer can utilize a non-local mail server (SMTP) in the event that you have authentication confirmation.

  • Integrated SMTP protocol support and authentication over SSL or TLS encryption type.
  • Can send an alternative plain text message of email for non-HTML email details.
  •  It can provide various kinds of error messages when it gets fails to connection or send an email.

You can get PHPMailer bundle from here.

You can utilize the mail server of an another host to send email, however for this, you initially need verification. For instance: to send an email from Gmail’s mail server you need a Gmail account in it. In the event that you are going to client Gmail’s mail server implies your need to turn on less security app in it.

SMTP is a convention utilized via mail customers to send an email to send a demand to a mail server. Once the mail server confirms the email it sends it to the goal mail server.

Here is a case of sending an email from Gmail’s mail server from your area. You needn’t bother with a local mail server to run the code. We will utilize the SMTP convention:

Step 1: Create a table to store the SMTP configuration details.

Step 2: Create a HTML  form for get the SMTP details from front-end. This form contains server name, port no, encryption type and username and password of the SMTP connection.

Step 3: Write the jQuery Ajax function to send the SMTP configuration form details into PHP store procedure.

Step 4: Write the PHP code to store the submitted values into MySQL database for future usage.

Step 5: Design the mail function form in HTML form with to address, Subject and Message keys and also write the form submitting procedure using Ajax function.

And jQuery function to mail form details submit to server,

Step 6: Here the final step to connect the SMTP server using our stored configuration details.

  • Include the PHPMailer class with our page,
  • Create a SMTP Object for including configuration details,
  • Set sender name and mail id with SMTP object,
  • Set receiver name and mail id wtih SMTP object,
  • If you want to add any attachments with mail use following line else avoid this,
  • Add mail subject, content and alternate details,
  • Finaly we ready to send the mail using send()
Final mail sending PHP script is,
Download

 

Learn Infinity

Learn Infinity is the most famous Programming & Web Development blog. Our principal is to provide the best online tutorial on web development. We execute the best tutorials for web experts this will help developers, programmers, freelancers and proving free resource you can download or preview the tutorials.

Leave a Reply

Your email address will not be published.

Back to top