Sunteți pe pagina 1din 1

SHARE

0
Home PHP Drupal WordPress Magento Jquery ASP.NET Technology Training  Contact Us


PHP 1 FOLLOW: 
0
NEXT STORY

Send Email via SMTP Server in PHP using PHPMailer How to Access Website without Domain
Name Assigned

BY ADMIN · PUBLISHED JULY 5, 2017 · UPDATED AUGUST 24, 2017

PREVIOUS STORY
Any web application may need send email through it’s script. In PHP, we use mail() function to send from web server
Configure SSH on cpanel and connect via
.However sometimes it may cause delivery issue.  putty to execute Magento command line
Means when we send email from php using just mail() function , sometimes recipient don’t receive the mail .To overcome on live server
this issue we need SMTP to send email .

   

PHP
Restore MySQL Database
from SQL File using PHP
13 MAR, 2018

JQUERY / PHP
Creating Price Range Slider
using jQuery in PHP with
SMTP is the most recommended way to send email .Using this email send from mail server rather than web server . MySQL
7 AUG, 2017
There a famous library available in PHP called ‘PHPMailer library’ .It allow to send email via SMTP having lots of
configuration . PHP
It allows to send plain text, HTML text . How to Access Website
without Domain Name
We have created below tutorials on how to send HTML email with SMTP in PHP using PHPMailer library. you can use Assigned
22 JUL, 2017
this script in your PHP website to send email.
PHP
[php_video_tutorial_banner]
Send Email via SMTP Server
in PHP using PHPMailer
Send HTML email 5 JUL, 2017

1 <?php MAGENTO
2 // Include and initialize phpmailer class
3 require 'PHPMailer/PHPMailerAutoload.php'; Configure SSH on cpanel and
4 $mail = new PHPMailer; connect via putty to execute
5  
Magento command line on
6 // SMTP configuration
7 $mail->isSMTP(); live server
8 $mail->Host = 'smtp.domain.com'; 19 JUN, 2017
9 $mail->SMTPAuth = true;
10 $mail->Username = 'hello@domain.com';
11 $mail->Password = '******';
12 $mail->SMTPSecure = 'tls';
13 $mail->Port = 587;
14    To search type and hit enter
15 $mail->setFrom('contact@domain.com', 'UnitedWebSoft');
16 $mail->addReplyTo('contact@domain.com', 'UnitedWebSoft');
17  
18 // Add a recipient
19 $mail->addAddress('xyz@gmail.com');
20  
21 // Add cc or bcc
22 $mail->addCC('cc@domain.com');
23 $mail->addBCC('bcc@domain.com');
24  
25 // Email subject
26 $mail->Subject = 'Send Email via SMTP using PHPMailer';
27  
28 // Set email format to HTML
29 $mail->isHTML(true);
30  
31 // Email body content
32 $mailContent = "<h1>Send HTML Email using SMTP in PHP</h1>
33     <p>This is a test email has sent using SMTP mail server with PHPMailer.</p>";
34 $mail->Body = $mailContent;
35  
36 // Send email
37 if(!$mail->send()){
38     echo 'Message could not be sent.';
39     echo 'Mailer Error: ' . $mail->ErrorInfo;
40 }else{
41     echo 'Message has been sent';
42 }

Send HTML Email with Attachments


Below demonstrate using addAttachment() function to send email with attachment. you can use multiple times the same
function to send multiple attachment as shown below .

1 // Add attachments
2 $mail->addAttachment('docs/unitedwebsoft_abc.pdf');
3 $mail->addAttachment('docs/unitedwebsoft_xyz.docs');
4 $mail->addAttachment('images/unitedwebsoft_123.png', 'hello.png');

Send Email to Multiple Recipients


We can also send the same email to multiple recipients using addAddress() function as shown below .

1 // Add multiple recipients


2 $mail->addAddress('xyz@gmail.com');
3 $mail->addAddress('doe@gmail.com');

Send Email using Gmail SMTP


We can also send email using our gmail SMTP details. to do so,first of all you need to change some setting in your gmail
account .
Follow below steps :

A er logging in gmail, go to the My Account page. Click the Signing in to Google link from Sign-in & security section.
Now on the same page, scroll down below ,find ‘Password & sign-in method ‘ section and turn O the ‘ 2-Step
Verification’
Again scroll down ,find ‘Connected apps & sites’ . Turn on there ‘Allow less secure apps’

Finally we can now send email using Gmail SMTP details. find below script . You have to mention your gmail details like
email,password, SMTP host and port.

1 // SMTP configuration
2 $mail->isSMTP();
3 $mail->Host = 'smtp.gmail.com';
4 $mail->SMTPAuth = true;
5 $mail->Username = 'unitedwebsoft@gmail.com';
6 $mail->Password = '********';
7 $mail->SMTPSecure = 'tls';
8 $mail->Port = 587;

If you have any query on this tutorials, write below on comment section . I will try my best to reply comments .
We also provide advance PHP course with e-commerce project based training. visit our website
www.unitedwebso .in/php-training-in-delhi.php

admin
Hi, I am Pawan Kumar a webmaster from New Delhi, India. I am developer and trainer at www.unitedwebso .in and www.w3-learn.com . I have

8 years working experience in PHP, Drupal, Wordpress, Magento, Jquery, Ajax, HTML 5, CSS3 etc. I have my proven quality records in web
Development and Training. I have completed more than 200 of web projects and trained more than 1000 of trainee .You can contact me through
my email: webmaster.delhi1@gmail.com . visit for my details Profile link

 YOU MAY ALSO LIKE...

0 0

Namespacing in PHP Bulk email import module


PHP Writing to a text file
MAY 6, 2015 OCTOBER 18, 2014
JANUARY 23, 2014

1 Comment unitedwebsoft 
1 Login

 Recommend t Tweet f Share Sort by Best

Join the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

All PHP Tricks • 5 months ago


Your tutorial is very easy to understand, i also wrote similar tutorial. https://www.allphptricks.co...
△ ▽ • Reply • Share ›

ALSO ON UNITEDWEBSOFT

Creating dynamic Photo Gallery with jQuery, PHP & MySQL Setting up PHP project from HTML Template
1 comment • 2 years ago 1 comment • 3 years ago
Abhisek Mahat — These instructions that you are posting are shilpa saini —
insufficient , I suggest you to add all necessary files and guidance to http://www.boardresultsnic2...http://www.boardresultsnic2...http://www.
help the users. Additionally adding a demo for the tutorial would be …

How to Become a Web Developer Learn PHP Best Web Designing and Development Training Institute
1 comment • 2 years ago 1 comment • 2 years ago
Rohit mehta — nice, thinklab also provide php training in AIM-IT Noida — Your article is very beneficial for me, really good
jaipur.http://www.thinklab.co.in/ information. www.aim-it.org offers everything you should know from
coding to designing to become an exceptional web designer. Our …

✉ Subscribe d Add Disqus to your site 🔒 Disqus' Privacy Policy



IT Training , PHP, Drupal, WordPress, Magento , Laravel ,Web Designing courses in Delhi/NCR © 2018. All
Rights Reserved.

S-ar putea să vă placă și