Mail script not working

“Relaying not permitted” suggests that you’re trying to send the email from an address that the SMTP server is not configured to use.

But if you get a parse error, I don’t understand how it’s even trying to send an email.

You can just press Enter every so often to get it onto multiple lines.

A message that you sent was rejected by the local scanning code 
that checks incoming messages on this system. The following 
error was given: "Relaying not permitted" ------ This is a copy 
of  your message, including all the headers. ------ 
Received: from mccwxyys by server165.web-hosting.com with 
local (Exim 4.96.2) (envelope-from [<em@icom-design.com>]
(mailto:em@icom-design.com)) id 1smxep-00Ei4a-05 for 
[em@icom-design.com](mailto:em@icom-design.com); Sat, 
07 Sep 2024 11:47:27 -0400 To: [em@icom-design.com]
(mailto:em@icom-design.com) Subject: MCCW Website 
Inquiry X-PHP-Script: [www.mccwimberley.com/formhandle.php]
(http://www.mccwimberley.com/formhandle.php) for 67.79.209.134, 
67.79.209.134 X-PHP-Filename: 
/home/mccwxyys/public_html/formhandle.php REMOTE_ADDR:
 67.79.209.134 Date: Sat, 7 Sep 2024 15:47:26 +0000 
From: Form Mail Handler [<em@icom-design.com>]
(mailto:em@icom-design.com) Reply-To: Information
 [<em@icom-design.com>](mailto:em@icom-design.com) 
Message-ID: [<U89pQgkgDzefwSprG44pVoXqb9LVT4oQknWTBXwFmA@www.mccwimberley.com>]
(mailto:U89pQgkgDzefwSprG44pVoXqb9LVT4oQknWTBXwFmA@www.mccwimberley.com) 
X-Mailer: PHPMailer 6.9.1 (https://github.com/PHPMailer/PHPMailer) 
MIME-Version: 1.0 Content-Type: multipart/alternative; 
boundary="b1=_U89pQgkgDzefwSprG44pVoXqb9LVT4oQknWTBXwFmA" 
Content-Transfer-Encoding: 8bit 
Sender: [<mccwxyys@server165.web-hosting.com>]
(mailto:mccwxyys@server165.web-hosting.com) --
b1=_U89pQgkgDzefwSprG44pVoXqb9LVT4oQknWTBXwFmA 
Content-Type: text/plain; charset=us-ascii 
Name: Ed Miller | Message: tes | Email: [em@icom-design.com](mailto:em@icom-design.com) --
b1=_U89pQgkgDzefwSprG44pVoXqb9LVT4oQknWTBXwFmA 
Content-Type: text/html; charset=us-ascii 
<ul> 
<li>Name:Ed Miller</li>
 <li>Email: [em@icom-design.com](mailto:em@icom-design.com)</li>
 <li>Message: tes</li>
 </ul>
 --
b1=_U89pQgkgDzefwSprG44pVoXqb9LVT4oQknWTBXwFmA--

So, should I check with the hosting company?

Looks to me like the FROM and TO email addresses are the same.

Just for testing. Does that make any difference?

That would probably be a good start, if you haven’t configured it yourself. The question is, which SMTP server is the site using, and does it allow emails to be sent from the address you specify here:

 $mail->setFrom('em@icom-design.com', 'Form Mail Handler');

I think you are right about that the site is using a different SMTP server. I just have not the foggiest idea how to handle that, sorry.

You’d have to ask the hosting company of the second site if the account in question is allowed to SMTP relay through their server.

It’s the same hosting company.
They send me this script:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';

if(isset($_POST['name']) && isset($_POST['email'])){
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $body = $_POST['body'];
    $namefrom = "Messages from the website";

    $mail = new PHPMailer();

    //smtp settings
    $mail->isSMTP();
    $mail->SMTPAuth = true;
//    $mail->SMTPDebug = SMTP::DEBUG_SERVER;  //Enable detailed debug log
    $mail->Host   = "smtpserver.mywebsite.com";
    $mail->Port       = 465;
    $mail->SMTPSecure = "ssl";
    $mail->Username   = "no-reply@mywebsite.com";
    $mail->Password   = "verysecurepassword123";
    
    //email settings
    $mail->isHTML(true);
    $mail->setFrom("no-reply@mywebsite.com", $namefrom);
    $mail->addReplyTo($email, $name); //Set reply-to address
    $mail->addAddress("admin@mywebsite.com");  //Set who the message is to be sent to
    $mail->Subject = ("Contact form: $subject from $name ($email)");
    $mail->Body = $body;

    if($mail->send()){
        $status = "success";
        $response = "Email is sent!";
    }
    else
    {
        $status = "failed";
        $response = "Something is wrong: <br>" . $mail->ErrorInfo;
    }

    exit(json_encode(array("status" => $status, "response" => $response)));
}

?>

Did they give you any additional instructions? It looks like they want you to use a defined SMTP server (replacing ‘mywebsite.com’ with the site’s address, etc.

It’s generally expected that you create a DOMAIN email account for handling emails FROM and TO that domain, so create something like info@mccwimberley.com and use that for your site.

OK guys,
In the interest of getting this thing over with, I have heeded Drummin’s advice and created an email account at mccwimberley.com, modified the PHP script and everything works now. Thank you for all your help, it is much appreciated.
Regards, Ed

1 Like