check the basic mail functions on a server

If it doesn't relate to Debian, but you still want to share it, please do it here

check the basic mail functions on a server

Postby say_hello » 2021-01-15 15:13

hi there dear folks

currenty work out some issues i have on a server. I need to check the basic mail functions... i have issues here

by the way and on a sidenote: i also checked some things in the php.ini: The php.ini has smtp_port = 25 set
but this function - we do not need for our checks... at the moment. .


below some of the tests - / note i tested some scripts -... all of them see below - with the results



mailtest10.php: Test-results: email sent - but no mail received at my inbox
taken from: https://conetix.com.au/support/simple-php-mail-test/

Code: Select all
<?php
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "My_testmai_adress_@mywebserver.com";
    $to = "My_testmai_adress_@mywebserver.com";
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
    $headers = "From:" . $from;
    mail($to,$subject,$message, $headers);
    echo "Test email sent";
?>



<<<<<<<<<<<<<<<<<<

mailtest20.php: Test-results: Error: Message not accepted

taken from: https://www.arclab.com/en/kb/php/how-to ... ction.html

Code: Select all
<?PHP
$sender = 'My_testmai_adress_@mywebserver.com';
$recipient = 'My_testmai_adress_@mywebserver.com';

$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;

if (mail($recipient, $subject, $message, $headers))
{
    echo "Message accepted";
}
else
{
    echo "Error: Message not accepted";
}
?>





<<<<<<<<<<<

mailtest30.php: Test-results: Testing PHP mail - this text was shown up

taken from: https://tekeye.uk/html/php-mail-script- ... il-sending

Code: Select all
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>PHP Mail Test</title>
    </head>
    <body>
        <h1>Testing PHP mail</h1>
        <?php
            //Use your test email address
            $to      = 'My_testmai_adress_@mywebserver.com';
            //Use an appropriate email subject
            $subject = 'A Test Email';
            $message = 'The quick brown fox jumped over the lazy dog. Then the fox jumped over the dog again.';
            //wordwrap long content
            $message = wordwrap($message, 70, "\r\n");
            $headers = 'From: some.body@example.com';
            //Send the email
            if(mail($to, $subject, $message, $headers))
            {
                echo 'Email sent out';
            }
            else
            {
                echo '<pre>';
                print_r(error_get_last());
                echo  '</pre>';
            }
        ?>
    </body>
</html>





<<<<<<<<<

mailtest40.php:Test-results: access denied-this text was shown up

taken form here: https://stackoverflow.com/questions/246 ... -of-e-mail

Code: Select all
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: yoursite.com';
$to = 'My_testmai_adress_@mywebserver.com';
$subject = 'Customer Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers .= 'From: from@example.com' . "\r\n" .
'Reply-To: reply@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);



<<<<<<<<<<<<<<


mailtest50.php: Test-results: access denied-this text was shown up!

taken from: https://stackoverflow.com/questions/388 ... is-enabled

Code: Select all
<?php

$email = "My_testmai_adress_@mywebserver.com";
$subject =  "Email Test";
$message = "this is a mail testing email function on server";


$sendMail = mail($email, $subject, $message);
if($sendMail)
{
echo "Email Sent Successfully";
}
else

{
echo "Mail Failed";
}
?>


<<<<<<<<<<<<<<<<



Well - now i will have a closer look at the server-conditions.


btw - besides the various scripts i found some other ressoruces that cover the topic-mail-deliverability and sending mails from a server: here i found a with explanaitions

https://stackoverflow.com/questions/246 ... -of-e-mail


interesting points here are some of the following:
Make sure mail headers have no syntax errors
Enable PHP's custom mail.log
See http://php.net/manual/en/mail.configuration.php for details. (It's best to enable these options in the php.ini or .user.ini or .htaccess perhaps.)
Make sure your form action value points to the correct location[/quote]

see more here: https://stackoverflow.com/questions/246 ... -of-e-mail



Look forward to hear from you..

regards
User avatar
say_hello
 
Posts: 26
Joined: 2019-10-13 09:58

Re: check the basic mail functions on a server

Postby reinob » 2021-01-16 13:21

From your message it's not clear what your problem or question is.
If you want to send e-mails from php using the mail() function then you need to have an e-mail server running at your web server.
mail() by default calls /usr/sbin/sendmail.

The most common option is to install postfix and configure it properly.

Given that you mention smtp_port I'm not sure if you're even running Linux at all, so I'd recommend you clear up first what you want to actually do, whether your server runs Linux or Windows (which uses the smtp_port option), and of course how you plan to configure your e-mail server.

It is very easy to get things wrong and end up being a spam source/relay, which in turn will land you in one or more blacklists.
reinob
 
Posts: 900
Joined: 2014-06-30 11:42


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 12 guests

fashionable