I'm trying to make code to send a simple mail via SMTP, I read that I must use the class phpmailer and also install pear engine on the server root, I downloaded some different files to authenticate the SMTP but always requires more files that I don't have or cant be charged. Actually, the PHP errors display this:
Warning: require_once(): open_basedir restriction in effect. File(/opt/plesk/php/7.1/share/pear/PEAR.php) is not within the allowed path(s): (/var/www/vhosts/necotec.es/:/tmp/) in /var/www/vhosts/necotec.es/httpdocs/prueba_smtp/Mail.php on line 48
Warning: require_once(/opt/plesk/php/7.1/share/pear/PEAR.php): failed to open stream: Operation not permitted in /var/www/vhosts/necotec.es/httpdocs/prueba_smtp/Mail.php on line 48
Fatal error: require_once(): Failed opening required 'PEAR.php' (include_path='.:/opt/plesk/php/7.1/share/pear') in /var/www/vhosts/necotec.es/httpdocs/prueba_smtp/Mail.php on line 48
I dont know if cant be found or is a permision problem the files by default takes 644 permisions in this server. Any clue would be helpfull thanks.
open_basedir restriction in effect
error means that some files or scripts are located out of allowed directory.
In your case this file is /opt/plesk/php/7.1/share/pear/PEAR.php.
In Plesk you can disable open_basedir(not secure): Domains > example.com > PHP Settings and set open_basedir to none.
Another way(more secure) is to set open_basedir as {WEBSPACEROOT}{/}{:}{TMP}{/}:/opt/plesk/php/7.1
I was able to configure PHPMailer on my test server(Plesk 17.5-17.8) using steps:
Logged in to the server using SSH
Went to domain Document root directory: # cd /var/www/vhosts/example.com/httpdocs/
Run the command taken from github: # composer require phpmailer/phpmailer
As a result "vendor" folder appeared in "httpdocs" folder.
Created a testmail.php file based on 0-send-email-plesk.php:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2; # 0 off, 1 client, 2 client y server
$mail->CharSet = 'UTF-8';
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPSecure = 'tls'; # SSL is deprecated
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'Plesk',
)
);
$mail->SMTPAuth = true;
$mail->Username = 'sender#example.com';
$mail->Password = 'password';
$mail->setFrom('sender#example.com', 'Name Surname');
$mail->addAddress('recipient#domain.tld', 'Name Surname');
$mail->Subject = 'Email subject';
$mail->msgHTML('Email content with <strong>html</strong>');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
It assumes that local mail server is used and Default Plesk self signed certificate is used by mail server: Plesk > Tools & Settings > SSL/TLS Certificates > Certificate for securing mail
Related
I've some problem trying to use phpmailer on my localhost.
I've been trying for at least 2 hours to connect my ionos 1&1 SMTP server using phpmailer.
<<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true); //Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.ionos.fr'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail#mymail.fr'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('anyrecipient#test.fr', 'Test');
$mail->addAddress('realadress#gmail.com', 'Joe User'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo '<br>' . 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
In fact, here is the error logs:
<2019-01-02 09:02:04 Connection: opening to smtp.ionos.fr:465,
timeout=300, options=array() 2019-01-02 09:02:04 Connection: opened
2019-01-02 09:02:15 SMTP INBOUND: "" 2019-01-02 09:02:15 SERVER ->
CLIENT: 2019-01-02 09:02:15 SMTP NOTICE: EOF caught while checking if
connected 2019-01-02 09:02:15 Connection: closed SMTP Error: Could not
connect to SMTP host. SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect
to SMTP host.
Any advise/clue?
Thanks a lot.
Read the docs & examples. You’re using SMTPSecure = 'tls' With Port = 465. It’s very well documented that that combination will not work. Either change to ssl or port 587, but not both.
i tried to configure SMTP in my Gitlab-Instance (following this guideline). but dont get it working.
gitlab.rb
gitlab_rails['gitlab_email_from'] = "admin#example.com"
gitlab_rails['gitlab_support_email'] = "admin#example.com"
#nginx['redirect_http_to_https'] = false
#nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.crt"
#nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key"
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = 'smtp.exmail.qq.com'
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = 'admin#example.com'
gitlab_rails['smtp_password'] = 'has been removed'
gitlab_rails['smtp_domain'] = 'smtp.qq.com'
gitlab_rails['smtp_authentication'] = :plain
gitlab_rails['smtp_enable_starttls_auto'] = true
production.log
Sent mail to i#example.com (8017.5ms)
mail.log
May 9 09:02:14 nday postfix/smtp[27203]: B16EF12019C: to=<i#example.com>, relay=none, delay=1049, delays=1017/0.04/32/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=mxbiz2.qq.com type=AAAA: Host not found, try again)s
May 9 09:02:14 nday postfix/smtp[27202]: 40274120CA7: to=<i#example.com>, relay=none, delay=988, delays=955/0.04/32/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=mxbiz2.qq.com type=AAAA: Host not found, try again)
BTW:I have changed the DNS and refresh. mail.log haven't logged my operation. It's old log.
Is your account new on Digital Ocean?
If yes, you need to ask them to unlock sendmail functionality.
This unlock is by account, not by droplet.
You will can use sendmail in all others droplets created by you after this unlock.
I used PHPMailer to send out email and it work perfectly fine on localhost. However, as client requested, we have to upload everything onto webmin. The PostFix Mail Server was being installed for us. The problem is that I could not get the email function to work on the server.
Here are my codes.
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body = 'Test Email';
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.xxx.xxx.xx";
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "";
$mail->Password = "";
$mail->SMTPSecure = 'tsl';
$mail->SetFrom('support#xxx.xxx', 'Support');
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "xxx#hotmail.com";
$mail->AddAddress($address, "Sara Chan");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Error message:
SMTP ERROR: Failed to connect to server: Permission denied (13) SMTP connect() failed. Mailer Error: SMTP connect() failed.
I have tried configuring the postfix main.cf file, but it still does not work.
I've tried:
http://postfix.state-of-mind.de/patrick.koetter/smtpauth/postfix_configuration.html
http://www.postfix.org/BASIC_CONFIGURATION_README.html
http://wiki.centos.org/HowTos/postfix
http://www.postfix.org/STANDARD_CONFIGURATION_README.html#null_client
Configuration from these links are different. I'm a new PHP programmer (Still an undergraduate student), and all these are really confusing. Right now, my postfix main.cf is back to its 'default' state. What should I do now?
It looks like you're using an old version of PHPMailer, so update that.
If you're sending from the same server as your script (which it sounds like you are since you're configuring postfix), don't use SMTP, call the IsMail() or IsSendmail() function instead of IsSMTP().
There's no such SMTP secure mode as 'tsl' - you're thinking of 'tls', and if you were going to use that it would probably be on port 587 rather than 25.
You won't need to supply auth credentials if you're sending via mail or sendmail.
I had the same error on a Oracle Linux 7.7 server and solved it by entering the following commands:
sudo setsebool -P httpd_can_sendmail 1
sudo setsebool -P httpd_can_network_connect 1
I have a problem, I'm using this project to use of base on my project. I tryied to get the same result of the guys project, and used the same project to test in my SQL.
I done the "index.php" works, and when I click "Save Route" it send a mensage "Updated", so, when I open "loady.htm" it give that error : "SintaxError: Unexpected Token < "
I used the same code, but changed the local host on process.php and the account and password.
But this is the unique change.
What's wrong on load.htm ? Or its an error on teste.php, I cant load the waypoints in "loady.htm"
Links for test:
www.inventoresdegaragem.com/dbteste/index.htm
and
www.inventoresdegaragem.com/dbteste/loady.htm
Edit 2: This is my process.php
<? ob_start(); header('Cache-Control: no-store, no-cache, must-revalidate');
#$data = $_REQUEST['*******'];
$host = 'localhost';
$usuario = '******';
$banco = '******';
$senha = '******';
$db = mysql_connect($host, $usuario, $senha);
mysql_select_db($banco, $db);
if($_REQUEST['command']=='save')
{
$query = "update mapdir set value='$data'";
if(mysql_query($query))die('bien');
//die(mysql_error());
}
if($_REQUEST['command']=='fetch')
{
$query = "select value from mapdir";
if(!($res = mysql_query($query)));
$rs = mysql_fetch_array($res,1);
die($rs['value']);
}
?>
Your process.php cannot connect to your database.
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'http' (1) in /home/i/inventoresdegara/www/dbteste/process.php on line 10
It would appear that your current live version of process.php does not have localhost specified as the server. Note that it should be just a server name and should not include the protocol:
$host = 'localhost';
$host = 'www.mydomainnamehere.com';
(or whatever domain name you want to use) and not
$host = 'http://www.mydomainnamehere.com';
I believe the error is occurring because the database error message I've reproduced above is formatted as HTML and starts with <:
<br />
<b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Unknown MySQL server host 'http' (1) in <b>/home/i/inventoresdegara/www/dbteste/process.php</b> on line <b>10</b><br />
The html on your "after" page is not valid
looks like jax.responseText is empty.
I would like to develop a simple email function in my PHP file, so I'm using the mail() function. When I try to send an email to myself, it doesn't work.
Here is my code:
$subject = "Hi";
$message = "Hello";
$from = "me#hello.com";
$header = "Form:".$from;
mail($from, $subject, $message, $header);
Here is the error message:
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\NFC\back.php on line 171
I think it is probably because the port is being used by other applications, so I tried to make changes to the php.ini file as follows:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 8080
However, it still gives the same message. What are the possible causes of this problem?