Is there a way to send mail in php online? - php

I can send emails in PHP because I edited the php.ini file the the XAMPP directory. Then I uploaded my PHP file in a free domain, I can't send the email anymore because the php.ini file is obviously for xampp only. How can I send an email on an online domain?

you can use 3rd party services like twilio and use their API to send the mails , you can even send whatsapp messages through that

You can also configure a email sending service for apps like Sendgrid or equivalent in order to be able to send out emails.
Most hosting providers block SMTP port 21 to avoid issues with spammers. The right way to do this is by using such a service I have suggested.

If you want to send mail with php, online, via Gmail...
Setup your project to use Composer.
https://getcomposer.org/
Add phpmailer to your project through Composer
https://github.com/PHPMailer/PHPMailer
composer require phpmailer/phpmailer
Configure your Gmail to be able to use smtp from php
Little tutorial regarding all described
https://netcorecloud.com/tutorials/send-an-email-via-gmail-smtp-server-using-php/
Following all the steps, you'll be able to work/use your code in localhost with xampp or online, without changing anything

Related

WordPress on VPS running Plesk, no mail is being sent out

I have a VPS server running PLESK(12.5.30) and all of the WordPress forms we have that are supposed to send to people who fill out forms, are not being sent. They are just sitting in the mail queue as 'deferred'.
I think it has to do with php mail, but I can't seem to get this to work and my host is literally no help at all. I even called Plesk and they did not help.
Any ideas?
Thanks!
For more information you can check system mail log somewhere in in /var/logs/
Take in account that setting up working server of outbound mail is a real pain. In two words you need to setup SPF and DKIM or such mail services like Gmail will mark all emails from your server as spam by default.
In your case I can suggest to SendGrid service which has a WordPress plug-in https://wordpress.org/plugins/sendgrid-email-delivery-simplified/
(You need to register SendGrid account, it's free)
If your contact forms using default wp_mail() you mail will be send through SendGrid mail servers.
Also you can setup you Postfix/sendmail with using SendGrid's mail server: https://sendgrid.com/docs/Integrate/Mail_Servers/postfix.html

Sending emails using XAMPP and PHP using Mac Yosemite

I am really confused on where to start with sending emails. I have search the web but the amount of content available for different packages and softwares has really confused me. I was wondering if anyone here had a simple or knows of a simple tutorial of how i can send an email using xampp.
Im new to using local host and so far have only used MySQL and Apache from xampp to load and view my php files for an application.
I would really appreciate it if anyone could help me start setting up XAMPP to send emails when i use the php.
Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!
is this link any good? http://www.websnippetz.com/2013/01/send-email-from-xampp-localhost.html
Many are using SendMail package with XAMPP but i can't find a download for that.
anyone tried anything which worked for them?
please help a very confused developer guys!
Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!
PHPMailer is not a server it is a library. People often recommend using a Mail library because the built mail functions are very low level and hard to work with. Because they are modeled after using sendmail from the commandline.
If you want to send via SMTP, use attachments, or other things it can be difficult or impossible to do with mail() directly.
Personally I recommend using SwiftMail over PHP mailer. IMO, it's more modern, easier to use, and has a better API, and depending on which PHP F/OSS projects you are used to using or contributing to its more common and the standard.
Overall there are 2 parts to sending mail from PHP:
Setup of the actual mail server on a system (local or otherwise)
The configuration of PHP to use that mail server.
To setup the mail function you need to install and configure a mail server locally in order to fulfill item (1). This should already be included and set up on OSX. So to fulfill item (2) you need to configure PHP via the INI to use that mail server by changing the sendmail_path.
Now if you want to use a library, which I recommend you need to get that source into your project and then use it appropriately. For the example we will use SwiftMailer, with SMTP transport via a gmail account:
require_once 'PATH/TO/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
->setUsername('user#gmail.com')
->setPassword('secret');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('My SMTP Message')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receipient#domain.com', 'other#domain.com' => 'A name'))
->setBody('Plain Text Message Body');
$mailer->send($message);
To send emails from your localhost your need an Email-Server like postfix or Exim or you send your E-Mails over SMTP what is described on that site from your link.
The easiest way is to use an abstraction layer like Swift Mailer
http://swiftmailer.org/docs/sending.html
Here you have a lot of possibilities to send E-Mails. Another solution is to install a local Mailserver and fetch all sending E-Mails. In MAMP Pro for example you have an integrated Mailserver.
http://blog-en.mamp.info/2009/09/how-to-sending-emails-with-mamp-pro.html

XAMPP mailtodisk feature

This is probably a stupid question but I can't seem to find an answer anywhere. I have made a PHP mail script on localhost and I need to test it, all the emails are being forwarded to the 'xampp/mailoutput' file and I can view them as .txt files. Does this mean that my script is working fine? Or do I need to set up a tool such as 'TestMailServerTool' to test properly.
Yup If you're getting mail output that means php is sending emails successfully.
If you want to get proper email functionality you have to setup an SMTP server in your Windows System. You can also use other SMTP servers like gmail, yahoo or use one which is provided to you by your ISP or your Web Hosting providers.

php send email via gmail (php.ini) with php internal mail function (win7)

Is there anyway to send email via gmail (or other free provider) in php.
But I want to use php built in mail() function.
This solution is only for dev and staging.
Thanks
You can, using PHPMailer. And also check here to know details you should provide in your script so that you be able to send using Gmail SMTP.
Source
Plenty of walk-throughs and pre-made scripts/classes if you just used google. Unless you want to make yours from scratch.
If you don't want to use libraries but still want to send email via gmail, you have to setup SMTP server which sends email via Gmail. One very easy alternative is SSMTP. Setting up SSMTP is very easy.
http://tombuntu.com/index.php/2008/10/21/sending-email-from-your-system-with-ssmtp/
Hope it helps.

sending an email using MAMP and php scripts

Hi I am running MAMP on my mac to locally host a website. I want to send an email using php scripts. The stuff i looked online tells me about php scripts for emails but i am unable to send emails. I am guessing this has to do with MAMP settings or maybe i have to make changes to php.ini file but i cant find information regarding that. Can i send emails to my clients using my gmail address running php scripts. I am creating a signup page where once you signup successfully, the site sents you a welcome email. Can some body please guide me how to do this. I have used code from here:
http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
but this doesnt work.
i have used following settings:
$host = "ssl://smtp.gmail.com";
$port = "465";
MAMP is just Apache, MySQL and PHP and doesn't include a mail server. You could use postfix or, as you said, an external SMTP server.
If using Gmail make sure your account is setup to allow SMTP connections (it's off by default). This can be found somewhere in Settings in the web client. I'd recommend you test it with Mail or another mail client on your local machine to make sure Gmail is working as expected.
Finally (once the above is set up) SwiftMailer or PHPMailer are good mail libraries which can connect to remote SMTP servers. It'll save you a lot of headaches writing your own code, especially when it comes to file attachments and such.

Categories