How to send email with SMTP in php

0 votes

I need to send an email using SMTP. Previously I was using PHP mail() But now my client wants me to use SMTP.

Here is my code:

$payer_email = "Your Email";
$subject = "Your Subject";
$message = 'Dear '.$name.',
            Thank you for your purchase from '.$site_url.'. The details of your purchase are below.
            Transaction ID: '.$txn_id.'
            Item Name: '.$item_name.'
            Payment Amount: '.$payment_amount.'
            Payment Amount: '.$payment_status.'
            Paid to: '.$receiver_email.'
            Thanks and Enjoy!';

$headers .= 'From: ' .$from. "\r\n" .'Reply-To: ' .$from . "\r\n";
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers  .= "Content-Type: text/html; charset=iso-8859-1 ";

//mail to buyer
mail( $payer_email , $subject, $message, $headers );

Can someone please tell me any ideas or share any tutorial to do this?

Jun 24, 2022 in PHP by narikkadan
• 63,420 points
508 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to send email with PHPMailer - embed image in body?

Hello @kartik, I found the answer: $mail->AddEmbeddedImage('img/2u_cs_mini.jpg', 'logo_2u'); and on ...READ MORE

answered Oct 22, 2020 in PHP by Niroj
• 82,880 points
10,538 views
0 votes
1 answer

How to send email using php?

Hello @kartik 1.) Download PHPMailer, open the zip file ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,880 points
1,040 views
0 votes
1 answer

How to run process with realtime output in PHP?

Hello @kartik, This worked for me: $cmd = "ping ...READ MORE

answered Oct 20, 2020 in PHP by Niroj
• 82,880 points
3,567 views
0 votes
1 answer

How to check if a string is an email address in PHP?

Hello, Try this without regular expressions: <?php ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,880 points
3,212 views
0 votes
1 answer

How to remove a child with a specific attribute, in SimpleXML for PHP?

Hii, Just unset the node: $str = <<<STR <a> ...READ MORE

answered Nov 5, 2020 in PHP by Niroj
• 82,880 points
3,768 views
0 votes
0 answers

How to detect faulty JPEG in PHP? (Issue with SOFn, DQT or DHT JPEG marker missing before a JPEG SOS marker)

Is there a way to detect if ...READ MORE

Jun 7, 2022 in PHP by Kichu
• 19,050 points
665 views
0 votes
0 answers

Sending email with PHP from an SMTP server

I get an error: SMTP server response: 530 ...READ MORE

Jun 25, 2022 in PHP by narikkadan
• 63,420 points
426 views
0 votes
1 answer

SMTP connect() failed PHPmailer - PHP

 You need to add the Host parameter $mail->Host ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
4,026 views
0 votes
0 answers

Javamail Could not convert socket to TLS GMail

I want to send an email using ...READ MORE

May 2, 2022 in Java by Kichu
• 19,050 points
2,609 views
0 votes
0 answers

PHPMailer: SMTP Error: Could not connect to SMTP host

I am having trouble sending mail through ...READ MORE

May 8, 2022 in PHP by Kichu
• 19,050 points
2,839 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP