I am using PHP on a website and I want to add emailing functionality.
I have WampServer installed.
How do I send an email using PHP?
Writing the PHP Code to Send Email using Gmail SMTPzip file, use this link. Unzip the master. zip in your application directory and run following command from your application directory. Composer is the recommended way to install PHPMailer.
Send Email from Localhost with PHPSet SMTP credentials (host, username, password, and port). Specify sender name and email ( $mail->setFrom ). Set recipient email address ( $mail->addAddress ). Set email subject ( $mail->Subject ).
php ini_set("SMTP", "aspmx.l.google.com"); ini_set("sendmail_from", "[email protected]"); $message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = [email protected]"; $headers = "From: [email protected]"; mail("[email protected]", " ...
It's possible using PHP's mail()
function. Remember the mail function will not work on a local server.
<?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?>
Reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With