{"id":965,"date":"2021-10-19T08:06:10","date_gmt":"2021-10-19T08:06:10","guid":{"rendered":"https:\/\/lite14.net\/blog\/?p=965"},"modified":"2021-10-19T08:09:13","modified_gmt":"2021-10-19T08:09:13","slug":"how-to-use-phps-mail-function-to-send-emails","status":"publish","type":"post","link":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/","title":{"rendered":"How to Use PHP&#8217;s mail() Function to Send Emails"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg\" alt=\"See the source image\" \/><\/p>\n<p>To send emails directly from a PHP script, the first method is to use the built-in mail() function.<\/p>\n<p>To make use of the PHP send mail feature, users who host their PHP application or website on a local server must configure the Sendmail program by editing the php.ini file in their PHP installation directory.<\/p>\n<p>If you&#8217;re using a hosting server, Sendmail is almost always configured for you. However, you must ensure that your hosting provider permits manual management of the Sendmail service.<\/p>\n<p>Users of Hostinger can enable or disable this feature by logging into the hPanel and navigating to Emails -&gt; Mail Service Control.<\/p>\n<p>The Sendmail service is enabled by default. Nonetheless, double-check to ensure accuracy.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#Creating_a_PHP_Mail_Test_File\" >Creating a PHP Mail Test File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#How_to_Send_Emails_Using_PHPMailer\" >How to Send Emails Using PHPMailer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#Installing_PHPMailer\" >Installing PHPMailer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#Utilizing_PHPMailer_in_conjunction_with_Hostingers_SMTP\" >Utilizing PHPMailer in conjunction with Hostinger&#8217;s SMTP<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"Creating_a_PHP_Mail_Test_File\"><\/span>Creating a PHP Mail Test File<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>After ensuring that Sendmail is operational, we&#8217;ll create a PHP mail script file in the public html directory.<\/p>\n<p>How to do it:<\/p>\n<p>1. To access the Hostinger File Manager, navigate to Files -&gt; File Manager in hPanel.<\/p>\n<p>2. Double-click the public html folder and then on the top bar, click the New File icon. Give this new file the name testmail.php and then click Create.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/testmail-file-1024x453.png\" alt=\"New file: testmail.php\" \/><\/p>\n<p>3. To edit testmail.php, double-click on it. You may use the basic PHP code below, but you must adjust the parameters appropriately.<\/p>\n<p>&lt;?php<\/p>\n<p>ini_set( &#8216;display_errors&#8217;, 1 );<\/p>\n<p>error_reporting( E_ALL );<\/p>\n<p>$from = &#8220;test@hostinger-tutorials.com&#8221;;<\/p>\n<p>$to = &#8220;test@hostinger.com&#8221;;<\/p>\n<p>$subject = &#8220;Checking PHP mail&#8221;;<\/p>\n<p>$message = &#8220;PHP mail works just fine&#8221;;<\/p>\n<p>$headers = &#8220;From:&#8221; . $from;<\/p>\n<p>if(mail($to,$subject,$message, $headers)) {<\/p>\n<p>echo &#8220;The email message was sent.&#8221;;<\/p>\n<p>} else {<\/p>\n<p>echo &#8220;The email message was not sent.&#8221;;<\/p>\n<p>}<\/p>\n<p>?&gt;<\/p>\n<p>4. Once finished editing, click Save &amp; Close.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/edit-file-1024x458.png\" alt=\"Editing the testmail.php file\" \/><\/p>\n<p>5. Send the email by browsing to YourDomain\/testmail.php. Remember to replace YourDomain with the domain name that was used to create testmail.php.<\/p>\n<p>6. The recipient will receive the following message:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/test-email-1024x461.png\" alt=\"PHP mail test\" \/><\/p>\n<h4><span class=\"ez-toc-section\" id=\"How_to_Send_Emails_Using_PHPMailer\"><\/span>How to Send Emails Using PHPMailer<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>If you&#8217;re sending a large number of emails, it&#8217;s recommended that you use an external PHP mailing package. The native PHP mail() function is not designed to handle large volumes of email because it opens and closes a Simple Mail Transfer Protocol (SMTP) socket connection for each email.<\/p>\n<p>Numerous PHP mail packages are available, including Pear Mail and Swift Mailer. We&#8217;ll use PHPMailer in this article.<\/p>\n<p>PHPMailer is a widely used email sending library that supports sending emails via the mail() function or an SMTP server. It provides access to a set of email-sending functions, which simplifies the process of configuring PHP mail.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Installing_PHPMailer\"><\/span>Installing PHPMailer<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Installing PHPMailer is a breeze, especially if you already have Composer installed \u2013 this tool is included with many shared hosting plans.<\/p>\n<p>To manually install PHPMailer, connect to your hosting account via the SSH terminal as follows:<\/p>\n<p>1. Download and install the PuTTY SSH client from the PuTTY website.<\/p>\n<p>2. From your hPanel dashboard, navigate to Advanced -&gt; SSH Access and note the SSH IP address, port number, username, and password listed under SSH Access information.<\/p>\n<p>3. Launch PuTTY and fill in the Host Name (or IP address) and Port fields with your SSH credentials. After that, click Open.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/putty-configuration.png\" alt=\"PuTTY Configuration, highlighting the Open button\" \/><\/p>\n<p>4. When a command window appears, enter your SSH username and password. Bear in mind that PuTTY will not display the password, so do not be alarmed if it does not appear.<\/p>\n<p>5. Enter the cd public html command.<\/p>\n<p>6. Finally, enter the composer require phpmailer\/phpmailer command.<\/p>\n<p>7. Wait a moment for the installation process to complete.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/command-window.png\" alt=\"PuTTY terminal window\" \/><\/p>\n<h4><span class=\"ez-toc-section\" id=\"Utilizing_PHPMailer_in_conjunction_with_Hostingers_SMTP\"><\/span>Utilizing PHPMailer in conjunction with Hostinger&#8217;s SMTP<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>You can use PHPMailer to send PHP emails immediately after installation.<\/p>\n<p>In this section, we&#8217;ll demonstrate how to send email using PHPMailer via the Hostinger SMTP server:<\/p>\n<p>1. Access the hPanel and navigate to Emails -&gt; Email Accounts -&gt; Create New Email Account.<\/p>\n<p>2. Enter your new email address and password. After that, click Create. Bear in mind that you will be using this information to send email via PHPMailer.<\/p>\n<p>3. Return to the same page and navigate to Configuration Settings -&gt; Manual Configuration, noting the SMTP Host and Port.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/08\/configuration-settings-1024x421.png\" alt=\"Email configuration settings, highlighting the outgoing server (SMTP)\" \/><\/p>\n<p>4. Navigate to Files -&gt; File Manager in the hPanel dashboard. To create a new file, right-click the public html folder and select Add New. Create a file called testphpmailer.php and give it a name.<\/p>\n<p>5. Double-click the testphpmailer.php file and then copy and paste the code below, making any necessary modifications. Replace test@hostinger-tutorials.com with your Hostinger email address and EMAIL ACCOUNT PASSWORD with your Hostinger password.<\/p>\n<p>&lt;?php<\/p>\n<p>use PHPMailer\\PHPMailer\\PHPMailer;<\/p>\n<p>require &#8216;vendor\/autoload.php&#8217;;<\/p>\n<p>$mail = new PHPMailer;<\/p>\n<p>$mail-&gt;isSMTP();<\/p>\n<p>$mail-&gt;SMTPDebug = 2;<\/p>\n<p>$mail-&gt;Host = &#8216;smtp.hostinger.com&#8217;;<\/p>\n<p>$mail-&gt;Port = 587;<\/p>\n<p>$mail-&gt;SMTPAuth = true;<\/p>\n<p>$mail-&gt;Username = &#8216;test@hostinger-tutorials.com&#8217;;<\/p>\n<p>$mail-&gt;Password = &#8216;EMAIL_ACCOUNT_PASSWORD&#8217;;<\/p>\n<p>$mail-&gt;setFrom(&#8216;test@hostinger-tutorials.com&#8217;, &#8216;Your Name&#8217;);<\/p>\n<p>$mail-&gt;addReplyTo(&#8216;test@hostinger-tutorials.com&#8217;, &#8216;Your Name&#8217;);<\/p>\n<p>$mail-&gt;addAddress(&#8216;example@email.com&#8217;, &#8216;Receiver Name&#8217;);<\/p>\n<p>$mail-&gt;Subject = &#8216;Testing PHPMailer&#8217;;<\/p>\n<p>$mail-&gt;msgHTML(file_get_contents(&#8216;message.html&#8217;), __DIR__);<\/p>\n<p>$mail-&gt;Body = &#8216;This is a plain text message body&#8217;;<\/p>\n<p>\/\/$mail-&gt;addAttachment(&#8216;test.txt&#8217;);<\/p>\n<p>if (!$mail-&gt;send()) {<\/p>\n<p>echo &#8216;Mailer Error: &#8216; . $mail-&gt;ErrorInfo;<\/p>\n<p>} else {<\/p>\n<p>echo &#8216;The email message was sent.&#8217;;<\/p>\n<p>}<\/p>\n<p>?&gt;<\/p>\n<p>6. Once you&#8217;ve finished editing the code, click Save &amp; Close. To run the script, navigate to YourDomain.com\/testphpmailer.php in your browser&#8217;s address bar.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To send emails directly from a PHP script, the first method is to use the built-in mail() function. To make use of the PHP send&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-965","post","type-post","status-publish","format-standard","hentry","category-tech-how-to"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Use PHP&#039;s mail() Function to Send Emails - Lite14 Tools &amp; Blog<\/title>\n<meta name=\"description\" content=\"To send emails directly from a PHP script, the first method is to use the built-in mail() function.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use PHP&#039;s mail() Function to Send Emails - Lite14 Tools &amp; Blog\" \/>\n<meta property=\"og:description\" content=\"To send emails directly from a PHP script, the first method is to use the built-in mail() function.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/\" \/>\n<meta property=\"og:site_name\" content=\"Lite14 Tools &amp; Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-19T08:06:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-19T08:09:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/lite14.net\/blog\/#\/schema\/person\/551c62581e407fcec8cf1f76df97b5d2\"},\"headline\":\"How to Use PHP&#8217;s mail() Function to Send Emails\",\"datePublished\":\"2021-10-19T08:06:10+00:00\",\"dateModified\":\"2021-10-19T08:09:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/\"},\"wordCount\":880,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/lite14.net\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg\",\"articleSection\":[\"Technical How-To\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/\",\"url\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/\",\"name\":\"How to Use PHP's mail() Function to Send Emails - Lite14 Tools &amp; Blog\",\"isPartOf\":{\"@id\":\"https:\/\/lite14.net\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg\",\"datePublished\":\"2021-10-19T08:06:10+00:00\",\"dateModified\":\"2021-10-19T08:09:13+00:00\",\"description\":\"To send emails directly from a PHP script, the first method is to use the built-in mail() function.\",\"breadcrumb\":{\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage\",\"url\":\"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg\",\"contentUrl\":\"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lite14.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use PHP&#8217;s mail() Function to Send Emails\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/lite14.net\/blog\/#website\",\"url\":\"https:\/\/lite14.net\/blog\/\",\"name\":\"Lite14 Tools &amp; Blog\",\"description\":\"Email Marketing Tools &amp; Digital Marketing Updates\",\"publisher\":{\"@id\":\"https:\/\/lite14.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/lite14.net\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/lite14.net\/blog\/#organization\",\"name\":\"Lite14 Tools &amp; Blog\",\"url\":\"https:\/\/lite14.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lite14.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/lite14.net\/blog\/wp-content\/uploads\/2025\/09\/cropped-lite-logo.png\",\"contentUrl\":\"https:\/\/lite14.net\/blog\/wp-content\/uploads\/2025\/09\/cropped-lite-logo.png\",\"width\":191,\"height\":178,\"caption\":\"Lite14 Tools &amp; Blog\"},\"image\":{\"@id\":\"https:\/\/lite14.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/lite14.net\/blog\/#\/schema\/person\/551c62581e407fcec8cf1f76df97b5d2\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lite14.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/37de671670ea9023731c3f3ef83c84b6d7d6faeffecd87fb98e3ec10aecc15bd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/37de671670ea9023731c3f3ef83c84b6d7d6faeffecd87fb98e3ec10aecc15bd?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/lite14.net\/blog\"],\"url\":\"https:\/\/lite14.net\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use PHP's mail() Function to Send Emails - Lite14 Tools &amp; Blog","description":"To send emails directly from a PHP script, the first method is to use the built-in mail() function.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/","og_locale":"en_US","og_type":"article","og_title":"How to Use PHP's mail() Function to Send Emails - Lite14 Tools &amp; Blog","og_description":"To send emails directly from a PHP script, the first method is to use the built-in mail() function.","og_url":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/","og_site_name":"Lite14 Tools &amp; Blog","article_published_time":"2021-10-19T08:06:10+00:00","article_modified_time":"2021-10-19T08:09:13+00:00","og_image":[{"url":"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#article","isPartOf":{"@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/"},"author":{"name":"admin","@id":"https:\/\/lite14.net\/blog\/#\/schema\/person\/551c62581e407fcec8cf1f76df97b5d2"},"headline":"How to Use PHP&#8217;s mail() Function to Send Emails","datePublished":"2021-10-19T08:06:10+00:00","dateModified":"2021-10-19T08:09:13+00:00","mainEntityOfPage":{"@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/"},"wordCount":880,"commentCount":0,"publisher":{"@id":"https:\/\/lite14.net\/blog\/#organization"},"image":{"@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage"},"thumbnailUrl":"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg","articleSection":["Technical How-To"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/","url":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/","name":"How to Use PHP's mail() Function to Send Emails - Lite14 Tools &amp; Blog","isPartOf":{"@id":"https:\/\/lite14.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage"},"image":{"@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage"},"thumbnailUrl":"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg","datePublished":"2021-10-19T08:06:10+00:00","dateModified":"2021-10-19T08:09:13+00:00","description":"To send emails directly from a PHP script, the first method is to use the built-in mail() function.","breadcrumb":{"@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#primaryimage","url":"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg","contentUrl":"https:\/\/www.tutsmake.com\/wp-content\/uploads\/2019\/10\/Send-Email-In-PHP-using-Mail-PHP-Mail.jpeg"},{"@type":"BreadcrumbList","@id":"https:\/\/lite14.net\/blog\/2021\/10\/19\/how-to-use-phps-mail-function-to-send-emails\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lite14.net\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Use PHP&#8217;s mail() Function to Send Emails"}]},{"@type":"WebSite","@id":"https:\/\/lite14.net\/blog\/#website","url":"https:\/\/lite14.net\/blog\/","name":"Lite14 Tools &amp; Blog","description":"Email Marketing Tools &amp; Digital Marketing Updates","publisher":{"@id":"https:\/\/lite14.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lite14.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/lite14.net\/blog\/#organization","name":"Lite14 Tools &amp; Blog","url":"https:\/\/lite14.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lite14.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/lite14.net\/blog\/wp-content\/uploads\/2025\/09\/cropped-lite-logo.png","contentUrl":"https:\/\/lite14.net\/blog\/wp-content\/uploads\/2025\/09\/cropped-lite-logo.png","width":191,"height":178,"caption":"Lite14 Tools &amp; Blog"},"image":{"@id":"https:\/\/lite14.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/lite14.net\/blog\/#\/schema\/person\/551c62581e407fcec8cf1f76df97b5d2","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lite14.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/37de671670ea9023731c3f3ef83c84b6d7d6faeffecd87fb98e3ec10aecc15bd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/37de671670ea9023731c3f3ef83c84b6d7d6faeffecd87fb98e3ec10aecc15bd?s=96&d=mm&r=g","caption":"admin"},"sameAs":["http:\/\/lite14.net\/blog"],"url":"https:\/\/lite14.net\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/posts\/965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/comments?post=965"}],"version-history":[{"count":1,"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/posts\/965\/revisions"}],"predecessor-version":[{"id":967,"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/posts\/965\/revisions\/967"}],"wp:attachment":[{"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/media?parent=965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/categories?post=965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lite14.net\/blog\/wp-json\/wp\/v2\/tags?post=965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}