The PHP script is failing to send out email notifications

I am facing an issue with my website's contact form that is supposed to send out an email after the user fills it out and clicks submit, but it does not appear to be working.

Unfortunately, I do not have access to the mail server since it is hosted externally.

How can I go about debugging this problem?

<?php
 require_once "Mail.php";

 $from = "B A <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e881868e87a8898a8bc68b8785">[email protected]</a>>";
 $to = "B B <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa3a4aca58aada7aba3a6e4a9a5a7">[email protected]</a>>";

    if($subject!=""){
    $subject =$_REQUEST['subject'];
    }else{
    $subject = 'Lighter Contact Form';
    }

    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $msg=$_REQUEST['msg'];

    $port = "25";

    $body = "Name: $name \n\nEmail: $email \n\nMessage: $msg";
    $headers = 'From: '.$name.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

 $host = "imap.ox.registrar-servers.com";
 $username = "info@abc";
 $password = "password";


 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body);
?>

Answer №1

To ensure your email is sent successfully without any errors, it is recommended to verify for an error response when using the Pear Mail class:

if(Pear::isError($mail))
{
    die($mail->getMessage());
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Optimizing Background Images with IE 8 Stretch Cover in Bootstrap

Page Broken I've searched all over Stack Overflow for a solution to resolve this background image issue. I'm using Bootstrap for the boxes and removed any margins. The problem arises when setting the background as cover; in IE8, it doesn't ...

Having difficulty centering an image in HTML?

I've been struggling to get the image (logo) centered on the top bar! I've tried using align-self: center;, display:block;, but nothing seems to work. It feels like I'm missing something here! Click here for the codesandbox link to view the ...

Acquiring HTML form data using JavaScript

Although it may seem trivial, I'm facing a challenge. I have an HTML form that is dynamically generated by JavaScript and populated with initial data fetched from the server. The form is displayed correctly with the pre-filled data. My goal is to allo ...

Is it possible to create a pure CSS responsive square that is positioned to the top right of a div element of any size?

My current goal is to achieve the following task... I aim to position a square perfectly in one or both corners of the top right section of a div, ensuring it never exceeds the boundaries regardless of the div's size or dimensions that necessitate th ...

Combine all select commands in a relational table in MySQL into one JSON column

I have a table with headers that include the id and name of individuals. Additionally, there are multiple tables containing specific details about each individual, such as phone number, address, gender, birthplace, etc. How can I construct a SELECT comman ...

An issue has occurred with the HTTP request to a PHP file in Angular

When attempting to send an http request to my php file, I encountered the following error message Possibly unhandled rejection: {"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":" ...

Quick method to assign child iframe title as index.html <title>title</title>

Is there a simple method to dynamically update the <title> of my index.html based on the <title> of a child iframe? Take a look at my website for reference If the content within the iframe changes, will the title automatically update along wi ...

Can the JavaScript code be altered within the client's browser?

So, I'm using JQuery Validator on my webform to validate form data. However, I haven't added any validation on the server side. I'm curious if it's possible for a user to modify the code and bypass my validations in their browser. If th ...

What sets apart <?php ?> from <script language="php"></script>?

While I was following a PHP tutorial, I came across the use of the <script language="php"></script> tag to write PHP code. I tried to understand the difference between this and the traditional <?php ?> tag, as well as any advantages or di ...

The top value in CSS animation fails to change properly

Can anyone help me figure out why the animation doesn't work when I try to change the vertical position of a form using JQuery? I want the input field to smoothly move to its new position so that users can see it happening. Here is the JsFiddle link: ...

The HTML checkbox remains unchanged even after the form is submitted

On a button click, I have a form that shows and hides when the close button is clicked. Inside the form, there is an HTML checkbox. When I check the checkbox, then close the form and reopen it by clicking the button again, the checkbox remains checked, whi ...

Issue with Ajax request in Laravel failing to function when ad blocker is active

While utilizing Laravel to send Ajax requests, everything functions properly on localhost. However, once I test it on the live server with an adblocker enabled, it fails to work. Once the adblocker is disabled, the functionality returns. domain.com/sponso ...

Performing a search in Django using raw MySQL commands

I am currently in the process of developing a custom search engine that includes 4 search fields, aiming to search within a MySQL table. This snippet from my views.py covers the search functionality, pagination, and listing of the entire table data. def ...

Is there a way to transfer a significant volume of data from one webpage to another without relying on the POST

Currently, I am utilizing a web server framework that exclusively operates with GET requests. Presently, my task involves transferring a substantial volume of data (specifically the text content in a textarea) inputted by users onto another page where it i ...

Tips for resolving an error in PHP and MYSQL code where data is being selected from the incorrect table in the database

I am working on a PHP code with MYSQL. It involves selecting data from the database using a dropdown list with AJAX and displaying the results on the screen. I have three dropdown lists that are dependent on each other and each dropdown has its own table t ...

Align a button to the left or right based on its position within the layout

On the left side, there is dynamic text and on the right side, a button is displayed as shown below: <div class="dynamic-text"> {{ dynamicText }} </div> <div class="some-button"> < ...

Transferring data from Unity to PHP: Passing a variable's value

My PHP file is used for displaying a PDF file that contains variables retrieved from the following PHP file. $areaOfCircle; ... ... $pdf->WriteFixedPosHTML($areaOfCircle, 20, 50, 20, 50, 'auto'); In addition, I have included my Unity script b ...

Utilizing Jquery tabs for consistent height display

Currently, I am utilizing jquery tabs for showcasing various content. This is what my functions look like: $(function() { $( "#tabs" ).tabs(); }); I attempted to ensure all tabs have the same height by using this approach: var heightStyle = ...

Establishing a connection using stream_socket_client that includes the ability to set

Looking at this block of PHP code: $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); The number '60' in the code represents a timeout for the connection establishm ...

Incorporating text overlays on images that are compatible with responsive websites is a top priority for me

This is a piece of HTML code that utilizes bootstrap 3 for design purposes. The challenge faced is related to positioning text over an image. When resizing the browser, the alignment of the text with the background gets disturbed. Assistance is needed in r ...