Fatal Error: Uncaught Error on send

the mail() function

Moderators: egami, macek, gesf

Post Reply
diveability
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Apr 06, 2020 5:37 am

Sat Oct 24, 2020 5:58 am

I'm hoping someone can spot where I'm going wrong please. This is the error message when I click on SEND on the contac tform
Fatal error: Uncaught Error: Call to undefined function eregi() in /homepages/12/d229008969/htdocs/testing/contactus.php:104 Stack trace: #0 {main} thrown in /homepages/12/d229008969/htdocs/testing/contactus.php on line 104
This is my PHP -

Code: Select all

                                                             $to = 'bob@paradisimo.co.uk';
									$subject = 'Enquiry from the website';
									$contact_submitted = 'Your message has been sent.';

									function email_is_valid($email) {
									  return preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i',$email);
									}

									if (isset($_POST['contact_submitted'])) {
										$return = "\r";
										$youremail = trim(htmlspecialchars($_POST['your_email']));
										$yourname = stripslashes(strip_tags($_POST['your_name']));
										$yourmessage = stripslashes(strip_tags($_POST['your_message']));
										$contact_name = "Name: ".$yourname;
										$message_text = "Message: ".$yourmessage;
										$user_answer = trim(htmlspecialchars($_POST['user_answer']));
										$answer = trim(htmlspecialchars($_POST['answer']));
										$message = $contact_name . $return . $message_text;
										$headers = "From: ".$youremail;
										if (email_is_valid($youremail) && !eregi("\r",$youremail) && !eregi("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
										  mail($to,$subject,$message,$headers);
										  $yourname = '';
										  $youremail = '';
										  $yourmessage = '';
										  echo '<p style="color: blue;">'.$contact_submitted.'</p>';
										}
										else echo '<p style="color: red;">Please enter your name, a valid email address, your message and the answer to the simple maths question before sending your message.</p>';
									  }
									  $number_1 = rand(1, 9);
									  $number_2 = rand(1, 9);
									  $answer = substr(md5($number_1+$number_2),5,10);
								?>
and the form within the same php file

Code: Select all


form id="contact" action="contactus.php" method="post">
								  <div class="form_settings">
									<p><span>Name</span><input class="contact" type="text" name="your_name" value="<?php echo $yourname; ?>" /></p>
									<p><span>Email Address</span><input class="contact" type="text" name="your_email" value="<?php echo $youremail; ?>" /></p>
									<p><span>Message</span><textarea class="contact textarea" rows="5" cols="50" name="your_message"><?php echo $yourmessage; ?></textarea></p>
									<p style="line-height: 1.7em;">To help prevent spam, please enter the answer to this question:</p>
									<p><span><?php echo $number_1; ?> + <?php echo $number_2; ?> = ?</span><input type="text" name="user_answer" /><input type="hidden" name="answer" value="<?php echo $answer; ?>" /></p>
									<p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="submit" name="contact_submitted" value="send" /></p>
								  </div>
								</form>
Can anyone help please ?
Thanks
simonbrahan
php-forum Fan User
php-forum Fan User
Posts: 90
Joined: Mon Jun 08, 2020 2:00 am
Contact:

Sat Oct 24, 2020 12:50 pm

The number after the filename in your error tells you where to look; on line 104 of contactus.php, you have a call to a function eregi() that isn't defined.
User avatar
Strider64
php-forum GURU
php-forum GURU
Posts: 398
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI
Contact:

Mon Oct 26, 2020 5:18 am

Life is a fig newton of your imagination! https://www.miniaturephotographer.com
diveability
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Apr 06, 2020 5:37 am

Mon Oct 26, 2020 7:02 am

Strider64 wrote:
Mon Oct 26, 2020 5:18 am
eregi is also depreciated -> https://www.php.net/manual/en/function.eregi.php

use preg_match -> https://www.php.net/manual/en/function.preg-match.php
Hi

I've changed from eregi to preg_match and the fatal error has stopped but now it goes into a perpetual error loop on the if then else :-
if (email_is_valid($youremail) && preg_match("\r",$youremail) && preg_match("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
mail($to,$subject,$message,$headers);
$yourname = '';
$youremail = '';
$yourmessage = '';
echo '<p style="color: blue;">'.$contact_submitted.'</p>';
}
else echo '<p style="color: red;">Please enter your name, a valid email address, your message and the answer to the simple maths question before sending your message.</p>';
Any ideas please :help:
diveability
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Apr 06, 2020 5:37 am

Mon Oct 26, 2020 10:10 am

Sorted. Like a dummy I forgot the ! before the preg_match. It's now working.

Thanks
Post Reply