sending mails from php
was wondering if anyone could assist me to setup the system in order to send email using php mail() function
i managed to setup mailx so that it routes cli based email through o365, but php makes nothing
2 Replies
Hi there,
On my fresh CentOS 7 system deployment, I set this up in 3 simple steps:
Step 1, install all my dependencies to get PHP and email functionality via PHP working:
yum install -y epel-release yum-utils
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php73 php-mysqlnd
yum makecache
yum -y install php-PHPMailer
yum install -y php php-common php-opcache php-mcrypt php-cli php-gd php-curl
Step 2, make a basic PHP executable script file to send emails.
nano ~/1.php
My Script looks like this:
<?php
$result = mail("joedoe@example.com","testing","testing");
var_dump($result);
echo "mail sent at " . time();
Then make it an executable file with this:
chmod +x ~/1.php
Step 3, make sure PostFix is ready to send emails:
mkfifo /var/spool/postfix/public/pickup
service postfix restart
I think I ran into some issues while trying to send my first email without step 3. However, after a bit of research, I came across an online post describing how to resolve that with step 3. So I'm not sure if it's totally necessary, but it worked for me anyways.
Oh, and to send your email to "joedoe@example.com
", all you have to do at this point is execute the script via:
php ~/1.php
Cheers,
Arty
Step 3, make sure PostFix is ready to send emails:
mkfifo /var/spool/postfix/public/pickup service postfix restart
[[@astable] (/community/user/astable)] (/community/user/astable) 's reply pre-supposes you have installed, configured and have the postfix email server running on your Linode. If that's not the case, his solution is not going to help you out.
The PHP part of @astable 's response looks correct, however.
You'll need to open a support ticket and ask Linode to unblock ports 25, 465 and 587 in order for you to send mail from your Linode. Your response:
i managed to setup mailx so that it routes cli based email through o365, but php makes nothing
indicates you may have already done this.
-- sw