{"id":970,"date":"2024-05-05T15:07:08","date_gmt":"2024-05-05T15:07:08","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=970"},"modified":"2024-05-05T15:07:08","modified_gmt":"2024-05-05T15:07:08","slug":"php-mail-function","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/php-mail-function\/","title":{"rendered":"PHP Mail() function is not working on Hostgator | Hostinger | Online"},"content":{"rendered":"\n<p>I myself have faced this problem many times, when email or contact form is not working on my clients&#8217; website, today in this blog I am going to tell you how you can configure the contact form on your php website. There are many reasons why <strong>PHP Mail function is not working<\/strong>, some of which include:<\/p>\n\n\n\n<ol style=\"background-color:#e3f1f3\" class=\"has-background wp-block-list\">\n<li><strong>Check File Permissions<\/strong>: Ensure that the file containing your PHP code has the correct permissions set. It should be readable and executable by the server.<\/li>\n\n\n\n<li><strong>Server Configuration<\/strong>: Make sure that your server is configured to support PHP. Sometimes, servers may not be configured properly to handle PHP scripts.<\/li>\n\n\n\n<li><strong>Error Reporting<\/strong>: Enable error reporting in your PHP script by adding <code>error_reporting(E_ALL);<\/code> and <code>ini_set('display_errors', 1);<\/code> at the top of your PHP file. This will help you identify any errors that may be occurring.<\/li>\n\n\n\n<li><strong>Check PHP Syntax<\/strong>: Verify that your PHP code does not contain any syntax errors. Even small mistakes can cause the script to fail.<\/li>\n\n\n\n<li><strong>Check Form Action<\/strong>: Ensure that the form action attribute points to the correct PHP file that processes the form data.<\/li>\n\n\n\n<li><strong>Check Form Method<\/strong>: Verify that the form method (GET or POST) matches the method expected by your PHP script.<\/li>\n\n\n\n<li><strong>Test PHP Script<\/strong>: Try accessing the PHP script directly in your browser to see if it executes without any errors. This can help isolate whether the issue is with the form or the PHP script itself.<\/li>\n\n\n\n<li><strong>Server Logs<\/strong>: Check your server logs for any error messages or warnings related to the PHP script. This can provide valuable information about what might be going wrong.<\/li>\n<\/ol>\n\n\n\n<p>You can check why your mail function is not working by using any of the listed methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">You can test with a single PHP Mail function that it is working on your website or not <\/h2>\n\n\n\n<p>Test <a href=\"https:\/\/www.php.net\/manual\/en\/book.mail.php\">PHP Mail()<\/a> on your server, Create a file on your server with name test.php<\/p>\n\n\n\n<ol class=\"wp-block-list\"><\/ol>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php\n$to_address = &quot;test@somedomain.com&quot;;\n$subject = &quot;This goes in the subject line of the email!&quot;;\n$message = &quot;This is the body of the email.\\n\\n&quot;;\n$message .= &quot;More body: probably a variable.\\n&quot;;\n$headers = &quot;From: test@somedomain.com\\r\\n&quot;;\n\nif (mail($to_address,$subject,$message,$headers))\n{\n echo &quot;Message accepted&quot;;\n}\nelse\n{\necho &quot;Error: Message not accepted&quot;;\n}\n?&gt;<\/pre><\/div>\n\n\n\n<p><strong>Change<\/strong>\u00a0the\u00a0$sender and $recipient\u00a0with your email id in the code. so that you can receive responses<\/p>\n\n\n\n<p><strong>Upload the php file<\/strong>\u00a0to your hosting provider or server<\/p>\n\n\n\n<p><strong>Open<\/strong>\u00a0the uploaded php file in your browser to\u00a0<strong>execute the php script<\/strong>.<\/p>\n\n\n\n<p><strong>The output<\/strong>\u00a0show either &#8220;Message accepted&#8221; or &#8220;Error: Message not accepted&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Open your email to check, whether you received email or not?<\/strong> using PHP Mail Function<\/h2>\n\n\n\n<p><strong>If Message Delivered<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Everything Working Fine <\/li>\n<\/ul>\n\n\n\n<p><strong>If Not Delivered ?<\/strong> Then you can check following things <\/p>\n\n\n\n<p>Some providers restrict external recipients for PHP mail. Update the recipient ($recipient) in your code to a local recipient, using an email address from your server&#8217;s domain. For instance, if your server domain is <a href=\"http:\/\/www.yourdomain.tld\/\">www.yourdomain.tld<\/a>, the recipient&#8217;s email should be <a>someone@yourdomain.tld<\/a>. Upload the modified PHP file and try again.<\/p>\n\n\n\n<p>If the issue persists, adjust the sender ($sender) to a local email (using the same email as the recipient). Upload the modified PHP file and retry.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I myself have faced this problem many times, when email or contact form is not<\/p>\n","protected":false},"author":1,"featured_media":971,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[137,53,97,136],"class_list":["post-970","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-mail-not-working","tag-php","tag-php-7-4","tag-php-mail-function"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=970"}],"version-history":[{"count":1,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/970\/revisions"}],"predecessor-version":[{"id":972,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/970\/revisions\/972"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media\/971"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}