How to Send Emails From Your Web Server With the PHP mail() Function and PHPMailer
Most businesses choose to create a professional email account to boost their credibility and build customer trust. To accomplish this, you just need to buy a domain and set up your business email on an email client or a server.
If you build your website or web application with the PHP programming language, you can send emails directly from your web server. The PHP mail functionality enables you to create custom mail forms and send basic text-based emails to multiple recipients.
There are two ways to send emails in PHP ‒ using the built-in PHP mail() function or a mail-sending library such as PHPMailer.
In this article, we’ll cover the differences between PHPMailer and the mail() function, showing you how to send emails with both.
Download Glossary For Web Beginners
What Is PHP Mail?
PHP mail is a function for sending emails with PHP scripts. The built-in PHP function can target multiple recipients per email sending. However, it isn’t suitable for bulk emailing without using an external PHP mailing package like PHPMailer.
PHPMailer vs mail() Function: Pros and Cons
PHP mail allows PHP-based website administrators to send mail from their web server using PHP scripts. It’s a popular alternative to getting a third-party email hosting service, as the PHP function is integrated with the web server.
Sending emails in PHP is possible via the native PHP mail() function or an external PHP mailing package like PHPMailer. Here’s a brief coverage of each method, including their advantages and disadvantages:
PHP mail() Function
Mail() is a PHP function that uses PHP scripts to send simple emails. The mail function includes three mandatory parameters ‒ $to, $subject, and $message. Optional parameters to utilize include $headers and $parameters. We’ll cover them in more detail later.
This built-in PHP function returns a boolean value upon execution ‒ TRUE if the server successfully receives the email for sending or FALSE on failure.
Advantages:
- Pre-installed and ready to use, all you need is to have PHP.
- Backward-compatible, a PHP version change won’t break the script.
- Easy to learn.
Disadvantages:
- Hard to set up with SMTP – will trigger recipient spam filters.
- Not suitable for sending a large number of emails.
- The TRUE return value doesn’t guarantee email delivery.
PHPMailer
PHPMailer is a popular mail-sending library that supports the process via the mail() function or through a Simple Mail Transfer Protocol (SMTP) server. It gives access to a set of functions for sending mail, simplifying the manual PHP mail configuration process.
Advantages:
- Introduces complex email structures, such as HTML documents and attachments.
- Supports SMTP, and authentication is integrated over SSL and TLS.
- Can send a lot of emails in a short period.
Disadvantages:
- Requires installation.
- Steep learning curve.
How to Use PHPMailer to Send Emails
In this section, we’ll cover the steps of using PHPMailer to send mail. We recommend using an authenticated SMTP connection with PHPMailer to increase your emails’ deliverability against spam filters.
Installing PHPMailer
Installing PHPMailer is quite simple, especially when using Composer.
Note that Hostinger’s Premium and Business web hosting plans, as well as cloud hosting solutions, come pre-installed with two versions of this software.
Use the composer command to activate Composer version 1.10. If you need the new 2.0 version or you’re using PHP version 8.0 or later, execute the composer2 command.
Follow these steps to install PHPMailer manually:
- Connect to your account via an SSH client.
- From your hPanel dashboard, go to Advanced → SSH Access and take note of the SSH IP, port, username, and password under the SSH details.
- Open PuTTY and enter your SSH information in the Host Name (or IP address) and Port fields. Then, click Open.
- Once a command window appears, type in your SSH username and password and hit Enter. Remember that PuTTY will not display the password, so don’t be surprised if it doesn’t appear on the screen.
- Execute the following command to navigate to the public_html directory:
cd public_html
- Run the following command to install Composer:
composer2 require phpmailer/phpmailer
- Wait a moment until the installation process is finished. Here’s what it should look like:
Suggested Reading
Learn more SSH commands to help manage your server.
Understanding PHPMailer Components
To understand how PHPMailer works, let’s review each script component above.
use PHPMailer\PHPMailer\PHPMailer;
– imports the PHPMailer class to the global namespace.require '../vendor/autoload.php';
– includes various libraries that PHPMailer needs.$mail = new PHPMailer;
– creates a new PHPMailer object.$mail->isSMTP();
– tells PHPMailer class to use the custom SMTP configuration defined in the script instead of the local mail server.$mail->SMTPDebug = 2;
– detects if something goes wrong with the SMTP connection.$mail->Host = 'smtp.hostinger.com';
– this is where the SMTP server address should be specified.$mail->Port = 587;
– set the SMTP port here. We’ll pick SMTP port 587 as the default mail submission port for all types of SMTP data transmission.$mail->SMTPAuth = true;
– activates SMTP authentication.$mail->Username = 'mymail@myawesomedomain.tld';
– specify your email address here.$mail->Password = 'My$tr0ngPa55w0rd!;
– enter your email password here.$mail->setFrom('mymail@myawesomedomain.tld', 'Your Name');
– this is where you insert the sender’s email address.$mail->addReplyTo('mymail@myawesomedomain.tld', 'Your Name');
– informs the recipient which address they should reply to.$mail->addAddress('recipient@domain.tld', 'Receiver Name');
– insert the recipient’s address here.$mail->Subject = 'Checking if PHPMailer works';
– add the email subject here.$mail->msgHTML(file_get_contents('message.html'), __DIR__);
– reads an HTML message body from an external file. The file_get_contents() function will load the content from message.html, a local file located in the public_html directory, and include it in the message.$mail->Body = 'This is just a plain text message body';
– contains the mail message body.//$mail->addAttachment('attachment.txt');
– if you want to include attachments, add the file names and remove the double slash from this statement.if (!$mail->send()) {
– defines what happens when the script is executed.echo 'Mailer Error: ' . $mail->ErrorInfo;
– you will see an error message and details of the error if the script fails to send.} else {
– extends the if statement and describes what happens if the previous condition is not met.echo 'The email message was sent!';
– means the email sending process is successful.
Pro Tip
The SMTPDebug = 2; line is only applicable when you test a script and want to see how it operates. Remember to change it to SMTPDebug = 0; when you are done with the test to prevent receivers from catching the SMTP protocol delivery report.
Using PHPMailer with Hostinger SMTP
After installing PHPMailer, you can start sending emails in PHP.
In this section, we’ll show you how to send email through the Hostinger SMTP server using PHPMailer.
Pro Tip
If you are using Titan Mail, connect to its SMTP server via the 465 (SSL) port or the 587 (STARTTLS) port. Head to Emails → Configure Desktop App to see your email account configuration details, including the SMTP settings.
To do so, follow the steps below:
- Create an email account by accessing hPanel, then go to Emails → Email Accounts → Create email account.
- Fill in the new email address and set a password. Then, click Create. Remember this information as you will use it to send mail via PHPMailer.
- From the same page, go to Configuration Settings → Manual Configuration and take note of the SMTP Port and Hostname.
- Access the hPanel dashboard and navigate to Files → File Manager. Click on the public_html folder and select Add New to create a new file. Name the file phpmailer.php and click Create.
- Double-click on the phpmailer.php file, and copy and paste the code below after making all the necessary changes. Make sure to replace the mymail@myawesomedomain.tld and recipient@domain.tld with your existing domain and My$tr0ngPa55w0rd! with your email account password.
<?php require 'vendor/autoload.php'; use PHPMailer\PHPMailer\PHPMailer; $mail = new PHPMailer; $mail->isSMTP(); $mail->SMTPDebug = 2; $mail->Host = 'smtp.hostinger.com'; $mail->Port = 587; $mail->SMTPAuth = true; $mail->Username = 'mymail@myawesomedomain.tld'; $mail->Password = 'My$tr0ngPa55w0rd!'; $mail->setFrom('mymail@myawesomedomain.tld', 'Your Name'); $mail->addReplyTo('mymail@myawesomedomain.tld', 'Your Name'); $mail->addAddress('recipient@domain.tld', 'Receiver Name'); $mail->Subject = 'Checking if PHPMailer works'; $mail->msgHTML(file_get_contents('message.html'), __DIR__); $mail->Body = 'This is just a plain text message body'; //$mail->addAttachment('attachment.txt'); if (!$mail->send()) { echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'The email message was sent.'; } ?>
- After editing the code, click Save & Close. To execute the script, enter yourdomain.tld/phpmailer.php in your web browser.
Creating a PHPMailer Contact Form
Other than using PHPMailer to send out simple PHP mail, users can create various contact forms with it, such as feedback surveys.
Similar to previous PHP scripts, create a new PHP file in the public_html folder and name it formscript.php. Copy and paste the script below into the new file and modify the values accordingly:
<?php use PHPMailer\PHPMailer\PHPMailer; $msg = ''; if (array_key_exists('email', $_POST)) { require 'vendor/autoload.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->Host = 'smtp.hostinger.com'; $mail->Port = 587; $mail->SMTPDebug = 0; $mail->SMTPAuth = true; $mail->Username = 'mymail@myawesomedomain.tld'; $mail->Password = 'My$tr0ngPa55w0rd!'; $mail->setFrom('mymail@myawesomedomain.tld', 'Mr. Snuffles'); $mail->addAddress('recipient@domain.tld', 'Receiver Name'); if ($mail->addReplyTo($_POST['email'], $_POST['name'])) { $mail->Subject = 'PHPMailer contact form'; $mail->isHTML(false); $mail->Body = <<<EOT Email: {$_POST['email']} Name: {$_POST['name']} Message: {$_POST['message']} EOT; if (!$mail->send()) { $msg = 'Sorry, something went wrong. Please try again later.'; } else { $msg = 'Message sent! Thanks for contacting us.'; } } else { $msg = 'Share it with us!'; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Contact form</title> </head> <body> <h1>Contact us</h1> <?php if (!empty($msg)) { echo "<h2>$msg</h2>"; } ?> <form method="POST"> <label for="name">Name: <input type="text" name="name" id="name"></label><br> <label for="email">Email address: <input type="email" name="email" id="email"></label><br> <label for="message">Message: <textarea name="message" id="message" rows="8" cols="20"></textarea></label><br> <input type="submit" value="Send"> </form> </body> </html>
Pro Tip
Taking user input from $_POST and using it unsanitized is not safe due to cross-site scripting (XSS) attacks. To avoid this, check out the best practices for PHP variable sanitization.
Save your changes and run the script from your browser.
Here’s what the result will look like:
If a visitor submits a message via the form, they will get a confirmation. The form’s content will be sent to the email address you entered here:
$mail->addAddress('recipient@domain.tld', 'Receiver Name');
Pro Tip
If the PHPMailer contact form doesn’t work, change the $mail->SMTPDebug = 0; line to $mail->SMTPDebug = 2 to identify the cause. Don’t forget to remove the line or change the 2 to 0 after.
Visit PHPMailer’s official repository on GitHub to check out other examples of how to use this mail-sending library.
If you’re a WordPress user, use a contact form plugin like Formidable Forms, Contact Form 7, or WPForms to streamline the form-building process.
How to Send Emails Using the PHP Mail() Function
Another method to send emails directly from PHP is the built-in mail() function. To use the PHP mailer feature, users hosting their PHP application or site on a local server will need to configure a Sendmail program by changing the php.ini file in their PHP installation folder.
If you use a hosting server, Sendmail usually comes already pre-configured. However, you must ensure that your hosting provider allows you to manage the Sendmail service option manually.
By default, the Sendmail service is already enabled. Nevertheless, double-check to be sure.
Important! Titan Mail enables the PHP mail() function by default. Thus, you can’t switch it on or off in hPanel.
Understanding PHP Mail Components
To help you understand the PHP mail() function, we’ll review the components of the PHP script used in the previous section.
ini_set( 'display_errors', 1 ); error_reporting( E_ALL );
The first two lines above enable error reporting to inform you if the PHP script has failed to execute.
$from = "mymail@myawesomedomain.tld";
This line contains the sender’s email address. Most hosting providers forbid adding random email addresses here due to spoofing risk. Therefore, it’s better to use one with your domain name to execute the script successfully.
$to = "recipient@domain.tld";
The recipient’s email address goes here. Separate the email addresses with commas if you want to send multiple emails.
$subject = "Checking PHP mail";
Enter the email subject line here.
$message = "PHP mail works just fine";
Here, input the body of your email message.
$headers = "From:" . $from;
This line is commonly used to include additional headers like From, Reply-To, and Cc. You can separate them with the CRLF.
if (mail ($to,$subject,$message,$headers))
This script executes the mail() function and checks whether it has run successfully.
echo "The email message was sent.";
The message above will appear if the mail() function is executed successfully.
echo "The email message was not sent.";
Alternatively, you will see this message if the mail() function fails.
Although additional headers are optional, it’s essential to include the From header when sending mail. Otherwise, you’ll receive a notification like this:
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing.
For more information about the Sendmail function and its parameters, refer to the official PHP documentation.
Creating a Test File for PHP Mail
After assuring that Sendmail is active, create a PHP mail file inside the public_html directory.
Here’s how to do it:
- From hPanel, navigate to Files → File Manager to access Hostinger’s File Manager.
- Double-click the public_html folder and select the New File icon at the top. Name this new file testmail.php and hit Create.
- Double-click on testmail.php to edit it. You can use the basic PHP code below but change the parameters accordingly. We’ll describe the script components in more detail in the following subsection:
<?php ini_set( 'display_errors', 1 ); error_reporting( E_ALL ); $from = "mymail@myawesomedomain.tld"; $to = "recipient@domain.tld"; $subject = "Checking PHP mail"; $message = "PHP mail works just fine"; $headers = "From:" . $from; if(mail($to,$subject,$message, $headers)) { echo "The email message was sent."; } else { echo "The email message was not sent."; } ?>
- Click Save & Close once finished.
- Send the email by accessing yourdomain/testmail.php from your web browser. Remember to change “yourdomain” to the domain used when creating testmail.php.
Sending HTML Emails With PHP
PHP mail() function can also be used to send an HTML email. This format is highly customizable compared to a plain text message.
The process to send HTML mail is the same, but you need to include an HTML message and additional parameter headers this time.
Here is an example of a basic script to send an HTML email:
<?php ini_set( 'display_errors', 1 ); error_reporting( E_ALL ); $from = "mymail@myawesomedomain.tld"; $to = "recipient@domain.tld"; $subject = "Checking PHP mail"; $message = " <html> <head> <title>This is a test HTML email</title> </head> <body> <p>Hi, it's a test email. Please ignore.</p> </body> </html> "; // The content-type header must be set when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers = "From:" . $from; if(mail($to,$subject,$message, $headers)) { echo "Message was sent."; } else { echo "Message was not sent."; } ?>
How to Troubleshoot Common PHP Mail and PHPMailer Errors
In the following section, we’ll review some of the most common issues that might occur when using the PHP mail() function or PHPMailer and how to fix them.
Sender Address Rejected: Not Owned by the User
This error means the server could not authenticate the sender using the provided details. To fix it, check the email address you’ve used to send the message and ensure it corresponds to an existing one.
Also, make sure your Sender Policy Framework (SPF) is enabled. If you use Hostinger, check your SPF record by going to hPanel, and navigating to Emails → Email Accounts → DNS settings → Manage Email Delivery.
If the SPF record is enabled, it will be shown as Active.
Gmail Couldn’t Verify That Domain.TLD Sent This Message
If you see this warning when testing a PHP mail script, the cause might be one of the following:
- There is no SPF record in the domain’s DNS Zone. If the record is missing, or you’re using external nameservers, add a new SPF TXT record manually via hPanel or cPanel.
- You used invalid SMTP authentication details. Make sure to use an existing email address that belongs to you.
Mail Goes to the Spam Folder
There are various reasons why PHP mail might trigger spam filters. Some of the most common causes include:
- Misleading or spam-like subject. It usually happens when using terms such as “test” or “urgent.” Be sure to set a clear intent in the Subject line.
- Incorrect sender address. Adding the wrong address can invoke security measures to filter your email to prevent spoofing and scams.
- Using spam trigger words. Remove spammy words like “a great offer” and “this is not spam” from your message to increase your email’s credibility.
- Your mailing list doesn’t have an unsubscribe link. Ensure to include an unsubscribe button to prevent this issue and build reader trust.
Could Not Connect to SMTP Host
Newer PHP versions usually have stricter SSL behavior. If the PHP mail() function fails to execute after updating your PHP to the latest version, this might be what causes it.
Using PHPMailer with some hosting providers usually triggers this code error as well.
For example, according to the PHPMailer wiki, GoDaddy blocks outbound SMTP connections via ports 25, 465, and 587 to third-party servers like Gmail and Hotmail except their own. Furthermore, it doesn’t support integration with third-party SMTP servers.
Use the following script to resolve this error:
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) );
Important! Avoid implementing these changes globally in php.ini, as doing so allows insecure connections, a security issue that PHP addressed since version 5.6.
As Hostinger SMTP doesn’t have this issue, consider migrating to our business email service for a better mailing experience.
Conclusion
You can send emails with PHP using either the mail() function or a mail-sending library like PHPMailer. The former is suitable for sending small volumes of simple text-based messages, whereas the latter is better for sending bulk emails or creating contact forms.
You can leverage the built-in PHP mail function by creating a new PHP file in the public_html directory and executing the script in it using your web browser.
On the other hand, sending emails with PHPMailer requires installing the code library via Composer, setting up an email account for it, and configuring your hosting’s SMTP settings.
In this tutorial, we went over installing PHPMailer, creating a test script, and setting up a simple contact form. We also covered the process of sending emails with the PHP mail() function and how to troubleshoot common errors during the email-sending process.
We hope you found this tutorial useful. If you have any further questions, leave them in the comments section below.
PHP Mail FAQ
This section will answer some of the most frequently asked questions about PHP mail.
Can I Send Emails From PHPMailer to Gmail or Other Email Services?
It depends on your hosting provider. With GoDaddy, you can’t send mail to inboxes that implement SPF and DKIM email authentication protocols like Gmail, Yahoo, and Hotmail. However, this issue doesn’t persist with Hostinger. Contact your web host to clarify its SMTP settings and whether it supports PHPMailer with third-party SMTP servers.
How Can I Validate Email Addresses Before Using the PHP Mail() Function or PHPMailer to Send Emails?
You can use the filter_var() function and pass the email address to the FILTER_VALIDATE_EMAIL filter. This filter will verify the email’s validity, ensuring it doesn’t contain any unsupported characters or white spaces.
Comments
June 13 2017
Cool article, But I have a problem with this part: 'smtp', 'host' => 'smtp.mailgun.org', 'port' => 587, 'from' => array('address' => 'something@gmail.com', 'name' => 'You name here'), // Place things in '' ( quote ) here 'encryption' => 'tls', 'username' => 'yourUsername', // Place things in '' ( quote ) here 'password' => 'yourPassword', // Place things in '' ( quote ) here 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false,
June 14 2017
Hey, Can you elaborate?
June 15 2017
Hey, Can you provide more details? Do you get any errors?
June 18 2017
Thank you..it helped a lot......
February 23 2018
What is the SMTP Port number for Non-Secure?
February 27 2018
Hello, Niroj. To keep security up to date, Hostinger only allows sending mail through secure ports. Therefore, non-secure SMTP is not supported.
October 05 2018
I actually have a question. The problem is my browser is displaying what appears to be a dialog of the SERVER/CLIENT for each step of the behind the scene processing just before the "Message sent!" message. I just want the "Message sent!" to appear. also i set $mail->SMTPDebug = 2;
October 08 2018
Hello, Prasey. To disable the server-side message, you'd have to set your SMTPDebug value to 0. That way, you will only see a "Message sent!" message without any additional log information.
March 01 2019
Thanks Buddy, Worked great !
March 18 2019
Wow, thank you very much for the tutorials, they are very helpful.
May 10 2020
Thank You !!! Useful
June 08 2020
Just adding that, for people without SSH access and unable to install composer, they can still use PhpMailer. Please refer the below link https://stackoverflow.com/questions/48128618/how-to-use-phpmailer-without-composer
July 04 2020
I have been trying to test this code and realized that whenever I add the following lines I get error 500 use PHPMailer\PHPMailer\PHPMailer; require 'vendor/autoload.php'; Is this outdated?
July 07 2020
Hey there Jorge! :) To use that script you will need composer to be installed and enabled first. Please follow the guide here. If you still struggle with it, you can always message our support team! I am sure they will be happy to help! :)
August 09 2020
Whenever I put my ssh username and password the ssh command prompt automatically disappear .. how can i fix this
November 06 2020
Hey Suman. Make sure you are manually writing the SSH password. If you copy-paste it, it may not accept it and give you an empty response.
August 23 2020
Thank You, but the only thing is that I noticed that the mail was sent without and Avatar/Organization Picture and I don't know I can add that. Any Suggestion
November 06 2020
Hey there Joao. You can check this little thread here on how you can approach the task at hand.
September 09 2020
I have purchased domin and hosting but i didn't get it free 1 emailer so please tell....
November 11 2020
Hey Akshay! :) You can check here how to create your email in your new plan!
September 30 2020
for laravel smtp mail this works MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=***@gmail.com MAIL_PASSWORD=****** MAIL_ENCRYPTION=tls but this is not working for me MAIL_DRIVER=smtp MAIL_HOST=smtp.hostinger.in MAIL_PORT=587 MAIL_USERNAME=mail@mywebsite.com MAIL_PASSWORD=********* MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=mail@mywebsite.com MAIL_FROM_NAME="mail@mywebsite.com" error message "Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients ↵" Any suggestion ????
November 18 2020
Hey there Sujith. Please drop a line to our Customer Success and we will help you out with it! :)
October 05 2020
hey I tested your PHP mail but it doesnt send an email though it confirms it was sent successfully. Can you please help me?
November 18 2020
Hey Joel. If you are sending something like "test" or "hey" email, it may get caught by the spam filter. Please try sending a normal email as test. If you still have an issue afterwards, just drop a line to our Customer Success team.
November 29 2020
Hey i tried this method to send a mail by making a request from a javascript page and the $_POST seems to be always empty. If i set everything as queryparams and do a get request it works but I want to do a post request and add the info in the body.
February 09 2021
Hi there! Did you receive any error messages with error display enabled or found anything in your error_log? If you won't be able to resolve it on your own, don't hesitate to contact our Customer Success team to help you troubleshoot!
November 30 2020
require(vendor/autoload.php): failed to open stream: No such file or directory
February 09 2021
Hi there! If you're getting this error, the chances are your composer isn't working correctly. Refer to article over here on how to install it ;)
December 23 2020
This page isn’t working mywebsite.com is currently unable to handle this request. HTTP ERROR 500
February 09 2021
Hi there! You'll find how to overcome error 500 over here - it will help you understand which line of code is an error and fix it :)
September 07 2021
I am trying to send mails through PHP Mail component through contact form of website. But HTTP Error 500 responds every time. Is web server not suitable for PHP Mail service ?
September 20 2021
Hi there, HTTP 500 error suggests that there's likely an issue with the code of the file you're trying to execute. I'd suggest to look through your code again with a PHP error log or error display :)
September 29 2021
Hi there! I have tested sending mails by following your phpmailer tutorial and it worked. Great tutorial. Thanks!
September 29 2021
Happy it worked out!
October 04 2021
Sending the testmail through my browser doesn't work. When I type mydomain.com/testmai.php in a chrome address bar.l It takes me to the website 404 page not found.
October 05 2021
Hi Terry, please make sure to double-check your URL - it looks like you might be missing an L at the end of your URL - mydomain.com/testmail.php If anything, double-check the directory in which you placed your testmail file and ensure it's correct. Good luck!
January 15 2022
My site php mail() function is not working, please what should I do?
January 18 2022
Hi Eddy, first thing I would check what error you're receiving when you try to run it. If it suggests a code error, I would check to make sure the code and values inside of your phpmailer file are correct. If it says that the email is sent, but you don't receive it, there might be an issue with your sendmail service, emails going to spam, lack of SPF or DKIM records. If that's case, I'd suggest to check with your host :)
March 19 2022
Nice tutorial. Please how do I go about creating and auto welcome email for anyone who registers in my website
March 22 2022
Hi there :) It would depend on what CMS/framework you're using for your website, but generally, what you're looking for is the script, which registers new users to include a trigger to send a PHP mail. Then simply create the PHP mail file with your desired content! Let me know how it goes for you :)
April 23 2022
if i were to use an SMTP Relay service (e.g., Mail Jet, SendGrid, MailGun) other than hostinger.com's SMPT. how would i go about updating the DNS mx record to work with those SMTP Relay services?
April 25 2022
Hi William! You'd need to (1) get the required MX and other necessary DNS records from the new service provider; then (2) change them on your Hostinger DNS zone like this. If you run into any issues, feel free to check in with our Customer Success team!
June 02 2022
thank you, it helpful
June 03 2022
Hi, please am trying to access my test.php file from an external html using ajax, but it's not working, used allow access origin in htaccess but still no good news
June 07 2022
Hi there! I'd suggest to start by looking at the permissions of your test.php file - it could be that they're not set well for what you're intending to do ?
July 08 2022
HI. Very useful tutorial - tx. I have a strange problem using PHPMailer 6.6.3 (also had it with 6.0.7). I can sent emails to addresses in my own domain and they are delivered ok. But any address not in my domain causes a PHPMailer instantiation failure - error message is 'Could not instantiate mail function.' It is perhaps worth adding that before I recently moved to Hostinger for hosting services, I never had this problem. Appreciate if you can shed any light on this. Tx
July 14 2022
Hey there. Chris! To help you further with this issue, please contact our Customer Success team from your account, as the issue would require a bit more information, but no worries! The team will be there to assist you further! ?
August 09 2022
Hello i used simple mail function to send otp but there is limit after 100 mail no mail sent .. How to resolve it
August 12 2022
Hey there! With the Sendmail function, you're able to send 60 emails per minute using PHP. If the limit is exceeded, the email service gets temporarily suspended. If you wish to send more emails, we would suggest using PHP Mailer. This way you would be able to send 200 emails per user / 500 per IP per hour using SMTP ?
December 11 2022
Can’t send emails telling me unable to authenticate I’ve changed passwords couple of times Still same error
December 15 2022
Hey! Please double-check your email configuration details for the PHP Mailer before trying to send emails, you can refer to this article to learn how to find them. If any issue persists, please contact our Customer Success team.
January 23 2023
I already used the free email to my web app. My question is, how many emails or what is the maximum number(if have) of emails that I can send everyday? My plan is Cloud startup Plan. Thank you for reply
January 26 2023
Hey there! With the free email services you can send up to 500 emails every 24 hours. You can check this article to learn how to check the limits for your email services.
March 04 2023
Thanks for the great job. My PHPMailer is sending email but keeps using the same subject for different OTP email notification even though they go with different subjects. That is, when the email is sent, the subject stays the same but when you toggle to see sender information, you'll get to see the actual subject inside. Help please
March 10 2023
Hello there! It seems there is an issue with your PHPMailer code, specifically the parts that are responsible for subject. I have found a similar issue raised in Github. However a correct troubleshooting requires your code, thus I would suggest to consult with PHPMailer developers on Github, I'm sure they will help you out!
March 09 2023
can i save the mail to the sent box then retrive it by imap ??
March 10 2023
Hey there! Yes, it's possible to sync different email accounts with tools like IMAP sync. All you will need to do is fill in both email accounts names, passwords and IMAP server hostname.
March 17 2023
Hello! Make sure that the sender is using isHTML() method properly, it must be specified after Body. More information can be found in this post.
April 04 2023
Hi, The contact form can send messages, but they can't be received at my email address. Please note: 1) the PHP mailer is already installed. 2) I have created and installed the formscript in the public_html folder. I tested the formscript with the browser, and it works fine. Messages can be sent from the formscript and be received at my email address. 3) I have read and followed the guidelines of Hostinger's article/tutorial: "Using PHPMailer with Hostinger SMTP." Still, the contact form on my website sends messages, but they can't be received at my email address.
April 07 2023
Hello there! Here's a couple suggestions what you could do: 1. Make sure that formscript.php file is updated to match with your existing email account details. Pay extra attention to the
$mail->addAddress('recipient@domain.tld', 'Receiver Name');
line as that needs to be changed. 2. Check the SPAM folder on the receiving inbox, the email could be there. 3. Try the script with different recipients and see if the email gets delivered. 4. Try out the simplified version of the mailer script called phpmailer.php, you can find the details about it in the same tutorial.June 06 2023
this is my .env file MAIL_MAILER=smtp MAIL_HOST=smtp.hostinger.com MAIL_PORT=465 MAIL_USERNAME=*email from email hostinger* MAIL_PASSWORD=my pasword MAIL_ENCRYPTION=ssl I have made sure to use a valid destination email, but when i send email with laravel mail, always error like this: Swift_TransportException Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients " Any suggestion?
June 08 2023
Hello, try adding this code to your .env file: MAIL_FROM_ADDRESS=you@email.com MAIL_FROM_NAME="you@email.com"
August 06 2023
i keep getting the error: Fatal error : Uncaught Error: Attempt to assign property "SMTPDebug" on null
August 11 2023
Hello there! Make sure you are using exactly same code as in tutorial to test out if everything works properly. Also make sure that PHPMailer is installed.
October 15 2023
This might mean that the object you created is null, likely indicating an issue with the creation or initialization of the PHPMailer instance.
August 25 2023
Hi, I met a problem with sending emails via SMTP. I'm using symfony mailer component and when I try to send an email, I've got this error: "Connection could not be established with host "smtp.hostinger.com:587": stream_socket_client(): php_network_getaddresses: getaddrinfo for smtp.hostinger.com failed: Temporary failure in name resolution" What can be the reason?
August 25 2023
Hello there! Seems like the script is not able to resolve hostname, I would suggest trying using an IP address instead of smtp.hostinger.com which is 172.65.255.143. Also check this Stackoverflow post as it's talking about similar issue.
October 18 2023
how can we save the email after sending it from PHPMailer?
November 03 2023
Hi there! Thanks for the question. To save emails sent via PHPMailer, you can configure your email server or email client to automatically save copies of outgoing messages. This is a convenient and hassle-free way to ensure that you have a record of all your emails, even if they are lost or accidentally deleted. I hope this helps! ?