Mail script not working

That’s the only log I found. I’ll ask the hosting company.

OK, found the log line:

[05-Sep-2024 17:50:40 UTC] PHP Parse error:  syntax error, unexpected ')' in /home/mccwxyys/public_html/formhandle.php on line 14

This is line 14:

  $mail->addAddress('em@icom-design.com',);

I don’t see this : ‘)’

Well, not meaning to butt in on this well established conversation but you didn’t actually show the form code but rather a picture of the form so we can’t see exactly how you structured those inputs.

As was already suggested, if you were to echo something in your processing code you could probably figure this out on your own.

Say for example you comment out most of your code and just echo “hi” on the page. Do you see hi or do you get an error.

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

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
$email = filter_var($_POST['Email'], FILTER_SANITIZE_EMAIL) || "not-a-valid-email@not-a-real-email.com";
$name = filter_var($_POST['Name'], FILTER_SANITIZE_STRING) || "Bad Name";
$textarea = filter_var($_POST['Message'], FILTER_SANITIZE_STRING) || "Message is missing!";	

echo "hi";
/*
$mail = new PHPMailer(true);
try {
  $mail->setFrom('em@icom-design.com', 'Form Mail Handler');
  $mail->addAddress('em@icom-design.com',);   
  $mail->addReplyTo($_POST['E-mail'], 'Information');
  $mail->isHTML(true);                                  //Set email format to HTML
  $mail->Subject = 'MCCW Website Inquiry';
  $mail->Body = '<ul>
                                   <li>Name:'.$_POST['Name']."</li>
                                   <li>Email: ".$_POST['Email']."</li>
                                   <li>Message: ".$_POST['Message']."</li>
                            </ul>";
  
  $mail->AltBody = "Name: ".$_POST['Name']." 
                             | Message: ".$_POST['Message']."
                             | Email: ".$_POST['E-mail'];
$mail->send();
    echo 'Dear ' . htmlspecialchars($_POST['Name']) . ',
    <br>Thank you for your message. 
    <br>I will respond as soon as possible.
    <br>Ed Miller
    <br>MCCW ';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
*/
?>

The reason I am bringing this up is two-fold in that you can learn to debug your own code and to point out something I noticed.
Your code is using $_POST['Email'] and $_POST['E-mail'] and I suppose one of these does not match your form, thus giving you an error.

1 Like

Drummin’s point is a good one about the email field. The log line you posted suggests that PHP really doesnt like that dangling comma. Get rid of it.

(Note that this may be indicating that the two servers you’re putting this code on are running different versions/configurations of PHP, which are complaining about different things)

2 Likes

Drummin: I copied/pasted the html but it showed as a pic, no idea why.
Tried it again, same thing.
Also, this is NOT my code. As I said in post #65, I know nothing about PHP, so unfortunately, I can’t figure things out on my own.
m_hutley: I did remove that dangling comma in line 14 ( $mail->addAddress(‘em@icom-design.com’,); and I get this error log:
[06-Sep-2024 15:28:37 UTC] PHP Fatal error: require(): Failed opening required ‘PHPMailer/src/Exception.php’ (include_path=‘.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php’) in /home/mccwxyys/public_html/formhandle.php on line 5
Again, I’m sorry being a nuisance.

Is PHPMailer a primary directory in the same location as this processing code?

Yes!

Is it capitalized the same way? (Some systems can be annoying pedantic like that…)

Does the file /PHPMailer/src/Exception.php exist? (Note: Specifically that filepath, from the root of public_html. No extra subdirectories, nothing?)

Well it’s more a matter of correct relative path as PHPMailer can be in any directory on the site. If for example his code is in a directory called comments and PHPMailer is outside this directory he can just back out of the current comments directory with ../

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

If PHPMailer is in a different directory, you can back out of your current directory (if needed) and go into that directory. For example

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

In any case you need to specify the relative path to PHPMailer from your processing code.

Use 3 back-tics on a new line. (on keyboard above Tab)
Paste your code on a new line.
Use 3 back-tics on a new line after your code.

OK, here it is again:

<form method="POST" action="https://www.mccwimberley.com/formhandle.php">
<input type="hidden" name="env_report" value="www.mccwimberley.com" />
<input type="hidden" name="recipient" value="em@icom-design.com">
<table border="0" cellspacing="0" cellpadding="0" width="250" bgcolor="#FFF7D6"><tr>
<td align="center" valign="middle" height="20" bgcolor="#638AC6" class="c14"><b>Inquiries</b></td>
</tr><tr>
<td width="250" align="left" valign="top" class="c13" style="padding-left:12px; padding-right:12px;"><br>&nbsp;&nbsp;&nbsp;If you have any questions regarding a menu, a recipe or about the club in general, please send the form below.
<br><br>&nbsp;&nbsp;&nbsp;<b>PRIVACY NOTICE:</b> We will <b>NOT</b> lease or sell your personal information!<br><br></td>
</tr><tr>

<td width="230" align="right" valign="middle" class="c13" padding-right:"12px;">Name:&nbsp;&nbsp;<input type="text" name="name" style="background:#EFE39C; color:#1030A5; font-family:verdana; font-size:11px;" size="26" maxlength="40"></td>

</tr><tr>
<td width="230" align="right" valign="middle" class="c13"><br>Email:&nbsp;&nbsp;<input type="text" name="email" style="background:#EFE39C; color:#1030A5; font-family:verdana; font-size:11px;" size="26" maxlength="40"></td>
</tr><tr>
<td align="center" valign="middle" class="c13"><br>Message:<br><textarea name="message" rows="10" cols="35" style="background:#EFE39C; color:#1030A5; font-family:verdana; font-size:11px;"></textarea>
<br><input type="hidden" name="email" value="em@icom-design.com"></td>
</tr><tr>
<td height="20" align="center" valign="middle" bgcolor="#FFF7D6"></td>
</tr><tr>
<td align="center" valign="middle" height="20" bgcolor="#638AC6" colspan="2"><input type="image" src="pics/submit.gif" value="Submit" width="94" height="20"></td></tr></table>
</form>

So in your form you are using name, email and message ALL lowercase so all your processing $_POST keys should be lowercase and $_POST['E-mail'] most definitely is not correct.

post #90:
No, that file/path does not exist.
post#94:
Corrected but no dice.

The file existed on your first server… why does it not exist on the second?

It does exist on the first server, just checked it, but it does not exist on the second one. Why, I don’t know.

So… the logical step at this point would be…

2 Likes

Guys, is this PHP thingy website- or server-specific or can I just ftp it down from the previous website and ftp it up to the current one?

All of the files other than the one we created (formhandle.php) are generic and should be identical on all servers it gets put on.

Great, thanks.

OK guys,
I have installed that PHPMailer onto the server, I have removed that “dangling” comma on the script and I still get the same error message:
[07-Sep-2024 15:23:00 UTC] PHP Parse error: syntax error, unexpected ‘)’ in /home/mccwxyys/public_html/formhandle.php on line 14

This is the current line 14: $mail->addAddress(‘em@icom-design.com’);

I also got this message, it appears there’s something wrong with the script:

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--

I did copy/paste but it shows as one long line, sorry about that.