Trying to Send Email from a PHP Script
In my cPanel domain and account, I am creating a simple HTML and CSS business website that uses PHP to send an email notification to request an estimate or to contact the business.
I created a cPanel email account to handle these type of emails, which I am using in my php script with the corresponding uid and pwd.
Currently I have the HTML, CSS, and PHP all together in one file that I call estimate.php
[PHP]require_once "../php/Mail.php";
require_once "../php/smtp.php";
require_once "../php/Net/SMTP.php";
$FirstName = $_POST['FirstName">;
$LastName = $_POST['LastName">;
$company = $_POST['company">;
$email = $_POST['email">;
$phone = $_POST['phone">;
$formMessage = $_POST['message">;
$to = '@';
$subject = '[TEST] Free Estimate or Quote Request';
$headers = "From: " . strip_tags($_POST['email">) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email">) . "\r\n";
$headers .= "CC: @yahoo.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//Incoming and Outgoing Server
$host = "ssl://";
$port = "465"; //SMTP: Port 465 IMAP: Port 993 POP3: Port 995
$username = "@";
$password = "";
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if(PEAR::isError($mail)) {
echo("
........................
........................
Line 49 would be require_once "../php/Mail.php"; It can't find the php/Mail.php file, but is there... It seems like the 'ROOT_PATH' is Not defined; I can't find the php.ini file and I don't know how to define the 'ROOT_PATH'.
" . $mail->getMessage() . "
"); } else { echo("Message successfully sent!
"); } ?>Free Estimate or Quote
First Name:
*
Last Name:
*
Company:
*
Your email:
*
Phone:
*
Question(s) and/or Comment(s):
Warning: require_once(../php/smtp.php) [function.require-once]: failed to open stream: No such file or directory in ../public_html/estimate.php on line 49
Fatal error: require_once() [function.require]: Failed opening required '../php/smtp.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /public_html/estimate.php on line 49
Line 49 would be require_once "../php/Mail.php"; It can't find the php/Mail.php file, but is there... It seems like the 'ROOT_PATH' is Not defined; I can't find the php.ini file and I don't know how to define the 'ROOT_PATH'.
-
This isn't really a server issue. I would ask this question at the HTML Help forums, you'll get some good help there. 0 -
[QUOTE]Line 49 would be require_once "../php/Mail.php"; It can't find the php/Mail.php file, but is there...
You may check the permission and owner of those file that are not accessible by your application.0 -
Where can I find the php.ini file? How do I set the ROOT_PATH in cPanel? 0 -
Hello :) You may want to try using the full path to the included files. EX: /home/$username/public_html/path/to/file.php
The php.ini file is stored at /usr/local/lib/php.ini by default. If you do not have root access, you can create your own php.ini file in /home/$username if your host uses a PHP handler that supports it. Thank you.0 -
cPanelMichael, I am pass that problem, now I need to configure PHP to use that mail server as its primary mail server. Where can I find the php.ini file so I can set the following options: <> SMTP " The hostname of your SMTP server; default is localhost <> smtp_port " The port for your SMTP server; default is 25 <> sendmail_from " The name and email to set for the from header <> sendmail_path " Path to sendmail or a sendmail-capable utility Currently I am getting the following failure: authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)] Please advise, thanks. 0 -
Those values should be configured in your PHP script and not in the php.ini file. I recommend consulting with your web hosting provider for assistance because they can review the existing php.ini file if necessary, or troubleshoot the 535 error. Thank you. 0 -
I got it working, thank you!! 0
Please sign in to leave a comment.
Comments
7 comments