Skip to content

Commit 69a2291

Browse files
committed
add new feature for mail checker
1 parent d4c34cf commit 69a2291

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Better handle error management for mysql test connexion
66
- Improve check with -1 value on PHP conf
7+
- Improve form for mail checker (allow to customize mailfrom and fix a return-path)
78

89
## 1.5.0
910

phpwpinfo.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
<?php /** @noinspection NotOptimalIfConditionsInspection */
2-
1+
<?php
32
/*
4-
Version 1.5.0
5-
Copyright 2012-2020 - Amaury Balmer (amaury@beapi.fr)
3+
Copyright 2012-2024 - Amaury Balmer (amaury@beapi.fr)
64
75
This program is free software; you can redistribute it and/or modify
86
it under the terms of the GNU General Public License, version 2, as
@@ -17,9 +15,6 @@
1715
along with this program; if not, write to the Free Software
1816
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1917
20-
1.5.0:
21-
22-
2318
TODO:
2419
[ ] Delete deprecated
2520
*/
@@ -1042,12 +1037,25 @@ public function html_form_email() {
10421037
$output .= '<td colspan="3">' . "\n";
10431038

10441039
if ( isset( $_POST['test-email'], $_POST['mail'] ) ) {
1045-
if ( ! filter_var( $_POST['mail'], FILTER_VALIDATE_EMAIL ) ) {// Invalid
1040+
if ( ! filter_var( $_POST['mail'], FILTER_VALIDATE_EMAIL ) ) { // Invalid
10461041
$output .= '<div class="alert alert-error">Email invalid.</div>' . "\n";
10471042
} else {// Valid mail
1048-
$mresult = mail( $_POST['mail'],
1049-
'Email test with PHP WP Info',
1050-
"Line 1\nLine 2\nLine 3\nGreat !" );
1043+
$subject = 'Email test with PHP WP Info';
1044+
$message = "Line 1\nLine 2\nLine 3\nGreat !";
1045+
$additional_headers = '';
1046+
$headers = 'X-Mailer: PHP/' . phpversion();
1047+
1048+
if ( isset( $_POST['mail_from'] ) && filter_var( $_POST['mail_from'], FILTER_VALIDATE_EMAIL ) ) {
1049+
$headers .= "\r\n" . 'From: ' . $_POST['mail_from'] . "\r\n" .
1050+
'Reply-To: ' . $_POST['mail_from'];
1051+
1052+
if ( isset( $_POST['mail_returnpath'] ) && '1' === $_POST['mail_returnpath'] ) {
1053+
$headers .= "\r\n" . 'Return-Path: ' . $_POST['mail_from'];
1054+
$additional_headers = '-f ' . $_POST['mail_from'];
1055+
}
1056+
}
1057+
1058+
$mresult = mail( $_POST['mail'], $subject, $message, $headers, $additional_headers );
10511059
if ( $mresult ) {// Valid send
10521060
$output .= '<div class="alert alert-success">Mail sent with success.</div>' . "\n";
10531061
} else {// Error send
@@ -1057,9 +1065,11 @@ public function html_form_email() {
10571065
}
10581066

10591067
$output .= '<form id="form-email" class="form-inline" method="post" action="#form-email">' . "\n";
1060-
$output .= '<i class="icon-envelope"></i> <input type="email" class="input-large" name="mail" placeholder="test@sample.com" value="">' . "\n";
1061-
$output .= '<button name="test-email" type="submit" class="btn">Send mail</button>' . "\n";
1062-
$output .= '<span class="help-inline">Send a test email to check that server is doing its job</span>' . "\n";
1068+
$output .= ' <i class="icon-envelope"></i> <input type="email" class="input-large" name="mail" placeholder="recipient@sample.com" value="">' . "\n";
1069+
$output .= ' <i class="icon-user"></i> <input type="email" class="input-large" name="mail_from" placeholder="mailfrom@sample.com" value="">' . "\n";
1070+
$output .= ' <i class="icon-user"></i> <label class="checkbox"><input type="checkbox" class="input-large" name="mail_returnpath" value="1"> Force Return-Path (only if mail from is set)</label>' . "\n";
1071+
$output .= ' <button name="test-email" type="submit" class="btn">Send mail</button>' . "\n";
1072+
$output .= ' <span class="help-inline">Send a test e-mail to check that the server is doing its job. You can leave the “mailfrom” field blank to let the server configuration “do its thing”.</span>' . "\n";
10631073
$output .= '</form>' . "\n";
10641074
$output .= '</td>' . "\n";
10651075
$output .= '</tr>' . "\n";
@@ -1070,10 +1080,9 @@ public function html_form_email() {
10701080
/**
10711081
* Stripslashes array
10721082
*
1073-
* @return array|string [type] [description]
1074-
*
1075-
* @param [type] $value [description]
1083+
* @param $value
10761084
*
1085+
* @return array|string
10771086
*/
10781087
public function stripslashes_deep( $value ) {
10791088
return is_array( $value ) ? array_map( array( &$this, 'stripslashes_deep' ), $value ) : stripslashes( $value );

0 commit comments

Comments
 (0)