iNSTALL Sending Email via PHP in CentOS 7 using Sendmail
If you are running a web server or a VPS, you may encounter the need of sending emails using your PHP application.
In the same way, if you are running a WordPress blog or you are using any kind of CMS and you would allow your visitors to send you emails using a Contact form (for example using the Contact Form 7 plugin for WordPress) you may need to install a simple program into your web server called sendmail.
«Sendmail is a general purpose internetwork email routing facility that supports many kinds of mail-transfer and delivery methods, including the Simple Mail Transfer Protocol (SMTP) used for email transport over the Internet.» via Wikipedia.
Sendmail can be simply installed using the package manager of your distribution.
Here are the instructions for installing Sendmail on CentOS 7.
Installation
In order to install sendmail on your CentOS 7 server, run the following command:
# yum install sendmail
Allowing your server to send emails
If you are using SELinux on your CentOS 7 server, you have to allow sendmail to send emails using the following command:
# setsebool -P httpd_can_sendmail=on
Send a test email using PHP
Enter the php interactive shell using this command:
https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-2118739050908640&output=html&h=280&slotname=4056756356&adk=357986283&adf=2374859675&pi=t.ma~as.4056756356&w=668&fwrn=4&fwrnh=100&lmt=1675496912&rafmt=1&format=668×280&url=https%3A%2F%2Ffasterland.net%2Fsending-email-via-php-centos-7-using-sendmail.html&fwr=0&fwrattr=true&rpe=1&resp_fmts=3&wgl=1&uach=WyJXaW5kb3dzIiwiMTQuMC4wIiwieDg2IiwiIiwiMTA5LjAuNTQxNC4xMjAiLFtdLGZhbHNlLG51bGwsIjY0IixbWyJOb3RfQSBCcmFuZCIsIjk5LjAuMC4wIl0sWyJHb29nbGUgQ2hyb21lIiwiMTA5LjAuNTQxNC4xMjAiXSxbIkNocm9taXVtIiwiMTA5LjAuNTQxNC4xMjAiXV0sZmFsc2Vd&dt=1675496911834&bpp=2&bdt=1532&idt=252&shv=r20230201&mjsv=m202301170101&ptt=9&saldr=aa&abxe=1&prev_fmts=0x0%2C300x1050&nras=1&correlator=5765546306295&frm=20&pv=1&ga_vid=88408484.1675496912&ga_sid=1675496912&ga_hid=85131008&ga_fc=1&u_tz=420&u_his=1&u_h=1080&u_w=1920&u_ah=1032&u_aw=1920&u_cd=24&u_sd=1&dmc=8&adx=773&ady=1522&biw=1903&bih=929&scr_x=0&scr_y=0&eid=44759876%2C44759927%2C44759842%2C31071722%2C44772269%2C44779794&oid=2&pvsid=2223789776107236&tmod=1340060923&uas=0&nvt=1&ref=https%3A%2F%2Fwww.google.com%2F&eae=0&fc=1920&brdim=0%2C0%2C0%2C0%2C1920%2C0%2C1920%2C1032%2C1920%2C929&vis=1&rsz=%7C%7CeEbr%7C&abl=CS&pfx=0&fu=128&bc=31&ifi=3&uci=a!3&btvi=1&fsb=1&xpc=OuL4eoNCTl&p=https%3A//fasterland.net&dtd=256
php -a
In the interactive shell, paste the following line of code:
mail (‘user@receiver.com’, “Test email”, “Test email from the Internet”, null, “-f user@sender.com”);
Don’t forget to replace user@receiver.com with the receiver email address and user@sender.com with the sender email address.
Viewing the sendmail log
In order to monitor the mail log, you can use this command:
tail /var/log/maillog
Once sendmail is installed on your web server you can allow your users to contact you via email using a contact form.