How to authenticate a local xampp server to send email - email

I once used int_set to send email from my company local xammp server for testing.
ini_set('SMTP','mail.companysite.com');
ini_set('smtp_port','26');
ini_set('sendmail_from','email#companysite.com');
Now our host has upgraded the server and we have to authenticate email sending. However I have not been able to get ini_set to work with authentication for email. How can this be done?
We are using xampp on windows machine.

I figured this out:
here is my code:
ini_set('SMTP','mail.somewebsite');
ini_set('smtp_port','26');
ini_set('sendmail_from','email#somewebsite');
ini_set('auth_username','email#somewebsite');
ini_set('auth_password','password');
$headers = "From:email#somewebsite\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
mail("email#gmail.com", "testing authentication", "hello world", $headers);

Related

Perl script getting 500 Internal Server error, end of script output before headers

I have this script to send email. Everything works except that after the email is sent I receive the error below. It has to be something simple I am missing. I checked and cgi file is 755 and since it gets to the sub and executes its got to be coder error. Any help greatly appreciated.
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
The error in the server log is:
[Tue Jan 17 16:00:23.475272 2023] [cgi:error] [pid 230679] [client 69.90.223.10:35014] End of script output before headers: test3.cgi
Here is the code I am using, Perl CGI on Linux
#!/usr/bin/perl -Tw
# use warnings;
use strict;
use Net::SMTP;
send_mail('mail.xxxxxxx.com', # Host
'order#xxxxxxxxx.com', #From
'yyyyyyy#gmail.com', #to
'Just a test, from mail.xxxxxx.com please ignore', #Message body
"Testing mail server email.\n" # Subject
);
exit;
sub send_mail {
my ($SMTP_HOST, $from, $to_addr, $body, $subject, $msg) = #_;
$msg = "MIME-Version: 1.0\n"
. "From: $from\n"
. "To: " . ( ref($to_addr) ? join(';', #$to_addr) : $to_addr ) . "\n"
. "Subject: $subject\n\n" # Double \n
. $body;
#
# Open a SMTP session
#
my $smtp = Net::SMTP->new( $SMTP_HOST,
Debug => 0, # Change to a 1 to turn on debug messages
Port => 587,
);
die("SMTP ERROR: Unable to open smtp session.\n")
if(!defined($smtp) || !($smtp));
die("Failed to set FROM address\n")
if (! ($smtp->mail( $from ) ) );
die("Failed to set receipient\n")
if (! ($smtp->recipient( ( ref($to_addr) ? #$to_addr : $to_addr ) ) ) );
$smtp->data( $msg );
$smtp->quit;
}
Checked File attributes they are 755
Since it ran the code an performed the send email the Char set should be correct
Being new to Perl not sure what else to check
This isn't a CGI program. You send no response for the request. Since there is no response (not even an invalid one), the script exits with nothing sent to standard output. The server realizes this is a problem, creates the 500 server error response, and adds to the error log that the script output ended before headers, which is the first thing the server expected to see.
You might want to start with a basic CGI tutorial to see how CGI works.
But, also realize that sending mail through a CGI program is a very 1990s thing to do. We don't typically do that anymore because we all figured out that letting anyone trigger mail through a public server was a bad idea.

Email Sent By Perl (Net::SMTP) Script Dropped Silently by Gmail

I have a Perl script that sends simple HTML emails to users with status updates and a link to more information. I'm creating mail with Net::SMTP and sending mail using smtp-relay.gmail.com. It has been working great for years.
In the last month, the emails stopped appearing - just gone with no errors and not in SPAM. Hours of troubleshooting later, I've narrowed the problem down to Gmail silently dropping emails that contain my specific URL.
http://DOMAIN/cgi-bin/requests/single_request.pl?requestid=111111
I changed one character and POOF! working again.
http://DOMAIN/cgi-bin/requests/single-request.pl?requestid=111111
I know this is a vague question, but what is going on? The workaround is fine, but I sure didn't learn anything about the root cause.
#!c:\strawberry\perl\bin -w
use strict;
use warnings;
use Net::SMTP;
use Net::Config;
# use this function to send email
#
# example:
#
# send_mail("RECIPIENT\#DOMAIN", "SUBJECT HERE", "BODY HERE");
sub send_mail{
my $recipient = shift;
my $subject = shift;
my $body = shift;
# connect to an SMTP server
my $smtp = Net::SMTP->new("smtp-relay.gmail.com", Debug => 0, Timeout => 30, Hello => 'REDACTED') or die "SMTP Connection Failed: smtp-relay.gmail.com";
# sender's address here
$smtp->mail('REDACTED');
# recipient"s address
$smtp->to($recipient);
# Start the mail
$smtp->data();
# Send the header.
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-Type: text/html; charset=\"UTF-8\" \n");
$smtp->datasend("To: $recipient . \n");
$smtp->datasend("From: REDACTED\n");
$smtp->datasend("Reply-to: REDACTED\n");
$smtp->datasend("Subject: $subject \n");
$smtp->datasend("\n");
# Send the body.
$smtp->datasend($body);
# Finish sending the mail
$smtp->dataend();
# Close the SMTP connection
$smtp->quit();
}
1;

PHP Mail not sending when hosted on Plesk

My first post and I really need some guidance, I have spent weeks researching and trying to understand why my mail code does not appear to be working on the corporate hosting(Plesk) vs. my personal hosting(CPanel) - (both on GoDaddy)
I have a number of areas within my site that I send emails, either to a newly registered user or when a user has downloaded software. The newly registered email I send works on both CPanel and Plesk
My problem is on the hosting of my personal website (CPanel), the following code works fine. However, when using the exact same code on my corporate hosting (Plesk) this does not work. I am pulling my hair out and would really appreciate a steer from you experts.
This is the code:
$to = "myname#myemail.com";
$subject = "Trial Software downloaded";
$headers.= 'From: "Test Mail" <noreply#myemail.com>';
$headers.= 'Reply-To: "Reply Mail" <noreply#myemail.com>';
$headers.= 'X-Mailer: PHP/' . phpversion();
$headers.= 'MIME-Version: 1.0';
$headers.= 'Content-type: text/html; charset=iso-8859-1';
$Message = 'Software Downloaded' . "\n\n" . 'The following registered user
has just downloaded a trial' . "\n\n" . 'Name: ' . $Fname . " " . $Lname .
"\n" . 'Company: '. $Company . "\n" . 'Email: '. $Email . "\n" . "Product: "
. $Product . "\n" . 'Date: ' . $a . "\n\n" . "An evaluation license for " .
$Product . " requires sending to " . $Email;
mail($to, $subject, $Message, $headers);

Sending PHP mail from Windows server

I have a form on my page. When the user hits the Send button - it's supposed to send an email with the details he entered in the form. Up until recently the form was hosted on a Linux server and I had no problem with it - the mail was sent and received. Recently I had to move to shared Windows server and since the move the mail is not sent. Here's the code that supposed to send the mail:
function send_contact_form($strName, $strEmail, $strPhone, $strMessage)
{
$to = 'mymail#mysite.com';
$subject = 'From the site';
$message = '<html lang="HE">
<head>
<title>
'.$subject.'
</title>
</head>
<body style="text-align:right; direction:rtl; font-family: Arial;">
Name: '.$strName.'<br>Email: '
.$strEmail.'<br>Phone: '.$strPhone
.'<br><br>Message: <br>'.$strMessage.'
</body>
</html>';
$email = $strEmail;
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$header .= "From: $email\r\nReply-To: $email" . "\r\n";
mail($to, $subject, $message, $header);
}
In a windows environment PHP uses SMTP insted of the Linux binary sendmail (or replacement)
You need to edit php.ini according to this page to be able to send e-mail via the mail() function.
On Linux, PHP uses an application called sendmail. Of course there is no similar applicaion on Windows. As php.ini file says, to be able to work with mail function, you need to setup mail server coordinates. If You don't have mail server, it is not possible to send emails from PHP. Of course You could use some external server like gmail.

How can I use PHP Mail() function within PHP-FPM? On Nginx?

I have searched everywhere for this and I really want to resolve this. In the past I just end up using an SMTP service like SendGrid for PHP and a mailing plugin like SwiftMailer. However I want to use PHP.
Basically my setup (I am new to server setup, and this is my personal setup following a tutorial)
Nginx
Rackspace Cloud
PHP 5.3 PHP-FPM
Ubuntu 11.04
My phpinfo() returns this about the Mail entries:
mail.log no value
mail.add_x_header On
mail.force_extra_parameters no value
sendmail_from no value
sendmail_path /usr/sbin/sendmail -t -i
SMTP localhost
smtp_port 25
Can someone help me to as why Mail() will not work - my script is working on all other sites, it is a normal mail command. Do I need to setup logs or enable some PHP port on the server?
My Sample script
<?
# FORMS VARS
// $to = $customers_email;
// $to = $customers_email;
$to = $_GET["customerEmailFromForm"];
$subject = "Thank you for contacting Real-Domain.com";
$message = "
<html>
<head>
</head>
<body>
Thanks, your message was sent and our team will be in touch shortly.
<img src='http://cdn.com/emails/thank_you.jpg' />
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <real-email#real-domain.com>' . "\r\n";
// SEND MAIL
mail($to,$subject,$message,$headers);
?>
Thanks
If found that on a new installation of Ubuntu 14.04 with nginx and PHP-FPM (no apache), neither postfix nor mailutils were installed.
I used:
sudo apt-get install postfix
(as in the recommended answer)
AND
sudo apt-get install mailutils
to get everything working on my server. Both were required. An entry in PHP.ini (as mentioned in the recommended answer) may also have helped, but without both of the other packages, it wouldn't have made a difference.
As there is no value for sendmail_from you need to set one in php.ini:
sendmail_from = "you#example.com"
Or in the headers when you call to mail:
mail($to, $subject, $message, 'From: you#example.com');
The email address should follow RFC 2822 for example:
you#example.com
You <you#example.com>
Failing that, have you actually installed a working email system?
If not, you can install postfix with the following command:
sudo apt-get install postfix
See below for more information on configuring postfix for use with PHP in Ubuntu:
https://serverfault.com/questions/119105/setup-ubuntu-server-to-send-mail