{"id":318,"date":"2025-01-07T10:53:52","date_gmt":"2025-01-07T06:53:52","guid":{"rendered":"http:\/\/keksus.com\/?p=318"},"modified":"2025-01-16T17:34:10","modified_gmt":"2025-01-16T13:34:10","slug":"simple-script-for-testing-the-sending-of-mail-on-a-local-linux-server","status":"publish","type":"post","link":"https:\/\/hostatto.com\/blog\/simple-script-for-testing-the-sending-of-mail-on-a-local-linux-server.html","title":{"rendered":"Simple script for testing the sending of mail on a local Linux server"},"content":{"rendered":"<p>First, create a shell script <strong>fakesendmail.sh<\/strong> in the folder \/usr\/bin\/<\/p>\n<blockquote><p>touch \/usr\/bin\/fakesendmail.sh<\/p><\/blockquote>\n<p>Add the following script to this file:<\/p>\n<blockquote><p>#!\/bin\/sh<br \/>\nprefix=\"\/var\/www\/mail\"<br \/>\nnumPath=\"\/var\/www\/mail\"<\/p>\n<p>if [ ! -f $numPath\/num ]; then<br \/>\necho \"0\" &gt; $numPath\/num<br \/>\nfi<br \/>\nnum=`cat $numPath\/num`<br \/>\nnum=$(($num + 1))<br \/>\necho $num &gt; $numPath\/num<\/p>\n<p>name=\"$prefix\/letter_$num.txt\"<br \/>\nwhile read line<br \/>\ndo<br \/>\necho $line &gt;&gt; $name<br \/>\ndone<br \/>\n\/bin\/true<\/p><\/blockquote>\n<p>Set permissions and make it executable<\/p>\n<blockquote><p>sudo chown root:root \/usr\/bin\/fakesendmail.sh<br \/>\nsudo chmod 755 \/usr\/bin\/fakesendmail.sh<br \/>\nchmod +x \/usr\/bin\/fakesendmail.sh<\/p><\/blockquote>\n<p>Create folders for local mail and set permissions<\/p>\n<blockquote><p>sudo mkdir \/var\/www\/mail<br \/>\nsudo chmod -R 777 \/var\/www\/mail<\/p><\/blockquote>\n<p>Set path to your script in php.ini<\/p>\n<blockquote><p>sendmail_path = \/usr\/bin\/fakesendmail.sh<\/p><\/blockquote>\n<p>Restart PHP.<\/p>\n<blockquote><p>service php8.3-fpm restart<\/p><\/blockquote>\n<p>To verify the sending of mail can use a simple php script<\/p>\n<blockquote><p>&lt;?php<br \/>\n$to = 'root@localhost';<br \/>\n$subject = 'Test letter';<br \/>\n$message = 'Hello.It works!';<br \/>\n$headers = 'From: 2hostatto@gmail.com' . \"\\r\\n\" .<br \/>\n'Reply-To: 2hostatto@egmail.com' . \"\\r\\n\" .<br \/>\n'X-Mailer: PHP\/' . phpversion();<\/p>\n<p>$send = mail($to, $subject, $message, $headers);<br \/>\necho ($send) ? \"Letter was sent!\" : \"Error sent!\";<br \/>\n?&gt;<\/p><\/blockquote>\n<p>If everything is fine in the folder <strong>\/var\/www\/mail\/<\/strong> you will see the file <strong>letter_1.txt. <\/strong>This is your sent letter.<br \/>\nFile <strong>num <\/strong>it`s letter counter.<br \/>\n<strong>Note:<\/strong> If the email was not sent, check the permissions on the created files and folders.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>...<\/p>\n","protected":false},"author":1,"featured_media":506,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[58,59],"class_list":["post-318","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-fake-sendmail","tag-shell-script"],"_links":{"self":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":0,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts\/318\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/media\/506"}],"wp:attachment":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/media?parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/categories?post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/tags?post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}