How to send emails using php via a localhost(MAMP) on Mac? - php

I am new to PHP and I am trying to build a form that will be used to send emails. The form has two inputs, one is for user email and the other is for the message. Once the user clicks on submit button an email is supposed to be sent to me.
I saw the PHP mail() function but I am not able to use it because I am on a local server that is MAMP and I am using Mac OS 11.4v,
PHP version: 7.4.12 ,
Apache Port: 80 (I don't know if this information will help but still I will provide it in case it does)
I saw various ways on the web to solve this problem but every solution is kind of different I am don't know what is right at this point. I know there are some changes to be made in the files of the MAMP folder but I don't know what are the steps and what will work.
Can anybody please help me out? Thanks in advance!

I've used a 3rd party SMTP service to send emails from local instances. I use Sendgrid since it's free for their lowest plan. The drawback is that you'd need to build the API integration with Sendgrid, so it's more work on that front.
I've also used Mailhog to intercept emails locally.
If you are developing WordPress locally, then the Sendgrid integration is ultra easy - just download the Sendgrid integration plugin.

I used the PHP mailer library and it worked.
Here is the link for the library: https://github.com/PHPMailer/PHPMailer/tree/5.2-stable
Go for the stable version of the library which is 5.2-stable. The instructions to use the library are provided in this GitHub link.
Remember you need a Gmail account from which you will be sending emails. You have to provide an ID and password for the same in the library. Also, you need to make this Gmail account less secure. Just search on google:- 'less secure apps' and you will find the link to make your account less secure.
For reference:- check out this youtube video:- youtube.com/watch?v=0luMSSesJBA

Related

How to Send Email from wordpress website using PHP and without any plugins?

Am a Dot Net Developer.I know how to send emails in Dot Net and thats quite easy.Recently I started learning wordpress and unfortunately strucked at the beginning itself just because of e-mail sending process.
I Read many article and answers as well from stackoverflow.Everywhere in a php mail() function they are showing the few parameteres (i,e; email_from.email_to,subject,...etc according to syntax of mail() function.)As a developer i know that it is required to give the password to authenticate for sending email.Where to give that password?.
I tried lot of ways following different people words. I put all smtp details along with password in php.ini file andalso tried in wp-config.php file.
But no use Am not getting any error in the application and even am not getting mail sendiing too.
So now my question is to please let me know the process of setting application to send email using mail() function without any plugins.
And is there any way to debug the php website using breakpoints with any app?
Please help me to learn.
-Thanks in advance...
To clarify the Wordpress itself can send mail messages such as notification or "Forgotten Password" messages and they are all using the 'mail()' function. If you are encountering an issue that displays that the 'mail()' is not working, then either:
You do not have the SMTP Enabled on your hosting environment (which happens on free hosting plans);
or
You need to create a email address 'wordpress#domain.com' where you replace the '#domain.com' with your domain of course.
With the information above your Wordpress will be able to send it's (system/notification) messages without any issues, but if you wish to send Normal mail messages using the Wordpress I am afraid that is not possible without a Plugin.

How to send an e-mail from a server on which I can't install anything?

I am hosting my website on https://www.gandi.net/en , thing is they don't allow connections over ssh only sftp.
I have a form on my website and want to allow user to contact me through that form. In other words an e-mail needs to be sent from form#mydomain.com to me#mydomain.com.
In order to do that there are a couple of options I tried, but none of them seems to work:
1) PHP's mail function: doesn't support authentification. In order to send an e-mail from form#mydomain.com I need to authenticate. And that doesn't seem to be possible with the mail-function
2) PHPMailer: I saw many people recommending this solution. I downloaded their sources and had a look. It seems like in order for it to work you need to actually install PHPMailer using composer. I can't run composer via sftp...
What other solutions exist? Or what workaround exists?
Thanks!
2) PHPMailer: I saw many people recommending this solution. I
downloaded their sources and had a look. It seems like in order for it
to work you need to actually install PHPMailer using composer. I can't
run composer via sftp...
You don't need to run composer, just download the PHPMailer files manually and upload it via sftp. Composer just makes it easier to install packages, the PHPMailer itself existed long before Composer was a thing.
If you don't know how to install it without Composer, take a look at this answer.
You can give swiftmailer a try: https://swiftmailer.symfony.com/
It is used by Yii2 Framework as well.
If I am not mistaken, for most if not all PHP extensions, you can integrate it into your website by using composer from your own development machine, and then you'd upload the source using FTP. You don't need to use composer on the host server.
I have used swiftmailer with Yii2 websites on a public host and I didn't have to do any special setup on the host.
If all else fails, change host. Get a refund and use your new host's web transfer services to move with minimum effort.
Looks like if you use a SPF TXT record in your DNS setup for their Simple Hosting package, you should be able to use mail() as-is without having to authenticate to your mail host:
# 10800 IN TXT "v=spf1 ip4:217.70.176.0/21 ip6:2001:4b98:c::/48 ip4:217.70.185.10 ip4:173.246.97.150 ip4:217.70.186.165 ptr ?all"
Source:
http://wiki.gandi.net/en/dns/zone/spf-record
Which has this quote:
This Simple Hosting records is only used if you plan to send e-mails through your website (via contact form, etc..)
After you've submitted each of these changes, be sure to activate the new version of your zone file, and keep in mind that it will take about 3 hours for it to take full effect due to the standard DNS propagation delay.
You can confirm the SPF TXT record is deployed using various online SPF testing tools.
Since a lot of users have the ability to edit StackOverflow posts, I recommend going to the source and copying and pasting the appropriate SPF record directly to avoid shenanigans. Also the Gandi Wiki will always have the latest list of IPs whereas this post may go stale after 6 months.
I recommend Composer-less CubicleSoft Ultimate E-mail Toolkit or one of the other already mentioned libraries over directly using the built-in PHP mail() function. The PHP mail() function is very misleading. It simply drops a properly prepared mail message into the mail queue on the local host. However, e-mail is very complex and really needs a library even for the most basic PHP mail() use-cases.
If you want to use one of the other Composer-enabled libraries but don't want to upload thousands of little rinky-dink files that comes with Composer-enabled software, then check out CubicleSoft Decomposer. Decomposer takes an entire Composer project tree and generates standalone builds with 1-2 files as the output.

Best way to activate mails for Wordpress hosted by Google Compute Engine?

I recently setup a Wordpress site hosted on Compute Engine, following these instructions. One step missing is how to activate emails for Wordpress. Once the installation is all done, if I try to reset my password from the Wordpress wp-admin login page, I get this error:
The e-mail could not be sent.
Possible reason: your host may have disabled the mail() function.
I see that outbound emails are not allowed by default on Compute Engine, and allowing outbound email sending for Wordpress installed in compute engine doesn't seem obvious. Could someone help with steps on how to do this?
Answer is outlined on Google Cloud Platform Documentation. But to sum up:
For the longest time SendGrid was the only solution. Google Cloud Platform has added Mailgun to the mix. Both require you to have a third party account, but both provide a better solution to handle all of the vagaries of email server administration than doing it yourself. You can setup either of these solutions as the hosts email method of choice following the directions they provide. Then you don't have to do anything to the Wordpress install to make it work, Wordpress will just use the underlying server config to send email.
You can also relay if you have Google Apps for Work.
Finally if you have your Google Cloud Project connected to your own network using VPN you can use your network to send the email.

Simple PHP contact form on Amazon Web Services EC2

I'm looking for a simple solution to get a simple PHP contact form to work on a Amazon EC2 LAMP stack. It seems like Amazon don't give you this functionality (mail()) and having searched around, the alternatives are far too excessive.
Option 1 -
Configure Amazon SES with PostFix
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-smtp-app.html
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/postfix.html
Option 2 -
Set up sendmail on the server. I'm fairly new to setting up linux servers and reading into this it's wanting me to configure and set up smtp servers which is way beyond me. Not entirely sure this would solve my problem either.
Can anyone point me towards any alternative options or point me towards strong documentation to guide me through?
Thanks
i think it's better to ask them here to allow you to use mail() function in PHP.
https://portal.aws.amazon.com/gp/aws/html-forms-controller/contactus/ec2-email-limit-rdns-request
Instructions mentioned in the following link can be followed. In this method installing postfix, sendmail or any other mail server is not required.
It uses the PHPMailer class to send email through Amazon SES using the SMTP interface.
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-php.html
It took me a whole day to reach this simpler solution.
https://stackoverflow.com/a/66457055/13150101

SilverStripe SMTP authentication instead of PHP mail() function

My hosting provider (webhosting.uk.com) for security reason has disabled the PHP mail() function requiring to update our code using a SMTP authentication. I have no idea how to change the code, I suppose it's in the sapphire folder? At the moment the contact form on my website doesn't send the email to the recipient and the newsletter module fails to send... Can anyone help me in this, or point me in the right direction?
Thanks in advance
Don't change the code in core - it will make updates complicated and isn't necessary.
There's a dedicated module for this problem: https://github.com/xeraa/silverstripe-smtp
Disclaimer: I'm the author, but it's free + BSD licensed so there's no reason for not using it.
I have the same issue with a site I maintain at webhosting. I've not yet resolved the issue (lack of time), but webhosting did provide an example way to use SMTP authentication for email sending.
This is the link the mail I got from webhosting: http://taverham.webhosting.uk.com/auth.txt. That asks you do download a zip file from here, which contains php script code that will allow you to use SMTP authentication.
Hope that helps!
Think I found the solution: http://www.silverstripe.org/general-questions/show/7991

Categories