How does Mail PHP work?

I came across the following script today for sending email using PHPMail.

<?php
    $to = "some_address@domain.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "my_address@domain.com";
    $headers = "From:" . $from;
    mail($to, $subject, $message, $headers);
    echo "Mail Sent.";
?>

      

The above can be launched via php mail.php

and instantly you will receive an email sent to $to

from $from

, despite not having to set up outgoing / incoming servers.

This really intrigued me as my CMS uses an outbound SMTP server (well, just like Mail PHP) which I need to configure with my Outlook SMTP name and password - something like validation.

However, about Mail PHP just .. sends an email. On the address you set it as. From the address you entered as.

Looking at the PHP docs it doesn't really show how it works. Mail PHP has no problem with spam since anyone can send to anyone at any time programmatically without checking the ID from

?

EDIT:

It's pretty funny what people in the comments were talking about POTUS, as I meant exactly what:

enter image description here

It ended up in my trash folder, but I'm sure it's not hard to make this look compelling enough and still count "oh damn spam filter lost my e-mail!"

+3


source to share


2 answers


The function mail

uses settings from php.ini. Details of this configuration can be found in Mail Runtime Configuration .

The default settings can be set in php.ini, although you can override them using ini_set

.

I'm pretty sure you've sent mail from a PHP script to a hosted server. This server may have preconfigured SMTP settings. If you try to do this locally on a WAMP / LAMP server, you will have to do this setting yourself, as PHP cannot read Outlook / WhateverMailclient settings.



As pointed out in the comments, you can specify the sender / sender yourself. SMTP doesn't require this to be the actual sender domain, so that's why this works. Invalid link is your host's pre-configured SMTP server.

Some relay servers check for this, and your mail may be blocked or sent to the junk mail folder. However, you can configure this in your DNS to indicate what is <Your server IP>

actually allowed to send email for <yourdomain>

. For more information on this subject, you can read this question on ServerFault .

+4


source


It uses smtp or send_mail protocol, you can even configure which php should be used to send emails in php.ini. It can send email, but the email will hit your spam filter to see in DKIM and SPF records for more information



0


source







All Articles