Email creation script for Wamp - php

I would like to make it available for clients to create emails through a web based interface without me having to go to mercury mail program and add a new user every time. i just need a source or script that will allow my clients to create emails on my wampserver email system.
I'm using MercuryMail as my mail host and i'm currently public with my server but need an email creation script that i can put into a web page. Preferably PHP.
Please help,
Thanks.

1) Open the “php.ini“. You should know where it is located because it depends upon the particular server you’re running.
2) Search for the attribute called “SMTP” in the php.ini file.Generally you can find the line “SMTP=localhost“. change the localhost to the smtp server name of your ISP. And, there is another attribute called “smtp_port” which should be set to 25.I’ve set the following values in my php.ini file.
SMTP = smtp.wlink.com.np
smtp_port = 25
3) Restart the apache server so that PHP modules and attributes will be reloaded.
4) Now try to send the mail using the mail() function ,
mail(“you#yourdomain.com”,”test subject”,”test body”);
you might get the warning like this,
Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\testmail.php on line 1
5) Now specify the following headers and try to send the mail again,
$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From: sender#sender.com’ . “\r\n”;
mail(“you#yourdomain.com”,”test subject”,”test body”,$headers);
Well that’s all, the mail is sent to “you#yourdomain.com” from the localhost.
Note : Some smtp server verifies the email address of the sender so the email address which is in the place of “sender#sender.com” should be a valid and existing email address otherwise mail might not be sent to the “you#yourdomain.com”.

Related

PHP send e-mail

Okay, so I'm new to php, and so I searched this site to find out how to send an e-mail to myself after a user fills out a contact form. I found this answer.
Send email with PHP from html form on submit with the same script
I'm using the code from the selected answer. I tried the top answer, by combining both sections into a single php page, and the second, using an html and php page, but I get the following errors:
Warning: mail() [function.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 (MY WEBSITE) on line 14
Warning: mail() [function.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 (MY WEBSITE) on line 15
"MY WEBSITE" was put there by me.
Lines 14 and 15 are these:
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
Why am I getting this issue? I'm doing exactly what the poster said to do.
You are running PHP on Windows. On Unix-like systems, PHP is able to use the built-in sendmail command to send emails, and so needs no further configuration. On Windows, however, that command doesn't exist, so PHP sends email via an external SMTP server.
In order to send emails, as the error messages explain, you will need to configure your php.ini file or use ini_set() to set the SMTP and smtp_port ini settings. You'll want to specify a SMTP server and smtp_port (usually 25) that you can send email from. If you are running php from your home computer, this would probably be whatever mail server your ISP gave you. If you are are on a third-party hosting provider, you would have to get email server information from them (and they may not actually allow sending email, or may put tight controls on how much you can send, to prevent spam).
The location of the ini file is set by both configuration and convention. PHP's configuration file documentation. On Windows, a long list of registry keys is checked, before eventually falling back to C:\windows or C:\winnt, so that is where you should look for your ini file. (Running php --ini will also show where it's actually trying to read the ini file from.)
There is a sample configuration file shown in the configuration file documentation. If you don't already have a php.ini that was installed when you installed PHP, you can use that format to guide you in creating a new file.
I would bet you are on a Linux server or the host server has the mail function built in turned off. You are not with out options though.
First consider your server. If your server is a shared server and you are likely to have your mail sent to spam if it is delivered at all. Most websites will out source their message systems to keep the load off the server and to ensure delivery.
If you are not in the market for outsourcing your mail services you will need to use a library that will do most of the heavy lifting for you. I would recommend phpMailer it even has an autoset up build in with great examples on how to configure your server.
Next before you install php mailer read your host servers fine print most of them have strict rules about mail (meaning you have to keep a confirmation they wanted the email) if they let you send mail at all. They do this to keep their servers off of spam list.
Good Luck

PHP Mail 550 Error [duplicate]

I am getting this error despite configuring php.ini to a valid send_from address. I know it is valid because it works when I send it from squirrel mail but when sending mail in php it will just not work. the invalid address presumably refers to the send_from address. so I can't see how it can think it's wrong. here is the php code:
$email="tobiasvogel1#googlemail.com";
$subject = "Your New Password";
$from="admin#dayshare.local";
$message = "Your new password is as follows:
xxxxxxxxxxxxxxxxxxxxxxxxxxx
This email was automatically generated.";
if(!mail($email, $subject,$message,$from)){
echo ("error");
}else echo "success";
and in php.ini:
SMTP = localhost
sendmail_from = admin#dayshare.local
550 Delivery is not allowed to this address
This error means that the sender is trying to send an email to an
address which he is not allowed to send to. This message is generated
after hMailServer has checked the IP range settings. As an example,
the default IP range configuration does not allow external users to
send messages to other external users. This is to prevent people from
using your server to send spam. So if an external user tries to send a
message to another external user, he will get this message.
That is the meaning of the error you are getting. This is from the hMailServer Documentation.
Can you try if the following will work?
<?php
mail('tobiasvogel1#googlemail.com','Test Email','This is a test email.',"From: tobiasvogel1#googlemail.com");
?>
If it doesn't work, then it's probably due to a misconfiguration in your hMailServer and you would need to check your hMailServer Logs.
The 4th parameter of the mail() function is not plain "from". In your code, you are only passing the email address without "From: " - The fourth parameter is for additional mail headers, so you have to format it like this:
mail($email, $subject,$message,"From: admin#dayshare.local\r\nX-Mailer: PHP");
I added another header as an example.
Try this, worked for me:
ini_set("sendmail_from", "info#yourdomain.com");
You need quotes and a semi-colon:
$email="tobiasvogel1#googlemail.com";
here is another solution - WAMP send Mail using SMTP localhost
KEEP IN MIND, everytime, after You change php.ini,
you must restart wamp (! ! !)
p.s. in php.ini, i have used:
SMTP = localhost
smtp_port = 25
sendmail_from = your_user#gmail.com
or if oyu cant edit php.ini, try to insert these lines in your php script.
ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
ini_set("sendmail_from", "your_user#gmail.com");

PHP text messages suddenly sending from a different address

I have a website that sends out text messages from the server. I'm using PHP for it:
$headers = "From: " . "Business Name <info#businessdomain.com>" . "\r\n";
$result = #mail( $to,$subject,$message,$headers);
Up until yesterday, the FRM: was always "Business Name" in the text message.
Suddenly, I'm now getting reports that FRM: is coming in as username#173.222.21.166 where username is my actual FTP account username (real IP not provided of course)!!
I definitely don't want to expose my FTP username. Is there something that would determine the FRM: name other than what I have set? I haven't changed the script at all... and suddenly it has changed.
UPDATE: using PHP mail not SMS Gateway
You can add a command line parameters to php's mail function, one of which is from.
mail($to, $subject, $message, $headers, '-finfo#businessdomain.com');
Note the -f directly infront of your from address
This may be related to the mail server on the local machine or the mail configuration on the local machine. There are certain settings, which can prevent faking the FROM header and substituting it by the actual user running the program that sends the mail.
I recommend checking the mail config for php and for the system itself.

php redirect email to file

I am using php5.
Are there some settings or a simple php.ini directive that would redirect all the emails to a folder?
I want on the development machine to have all the emails generated by the system not sent to the actual receiver but put in a folder.
Thanks.
I used to have some code like this (kinda pseudocode):
define ('DEBUG', true);
function send_email($to, $subject, $body) {
if (DEBUG) {
file_put_contents('some_folder/' . $to . date('dmY-His') . '.html', $body);
}else{
// Actual code to send email
}
}
But i agree with others, it's easier/better to setup an development email account to receive those emails.
I don't think you will be able to do something like this. Mails are sent by a mail server so it must be your mail server that writes them to a file instead of sending them.
Why not simply send it to a special development email?
Sample:
define('DEBUG', true);
if(DEBUG)
{
// Override recipient
$recipient = 'development#domain.tld';
}
// Send mail...
No settings that I'm aware of in PHP itself. However, if you're using Postfix on your development server, here's a recipe I cooked up to redirect all outbound email to a single (local) address:
/etc/postfix/main.cf: (add this to the existing file, don't replace everything)
virtual_alias_maps = regexp:/etc/postfix/virtual
/etc/postfix/virtual:
/.*/ duskwuff#localhost
You can configure your mail server to accept SMTP messages as normal, but make it unable to forward them onto another mail server. If your mail server supports it, make it redirect all messages to a postmaster account, or any other address of your choice.
This means that PHP will behave as normal, everything will appear to work straight away with the message, but it just won't go to the 'intended' recipient.
It also means that you can inspect headers (pretty much as they would normally appear), to support debugging.
There are many ways to do this. Basically, you need to define the sendmail command in your php.ini to point to a program or script which will save the mail locally.
One solution is this:
Catch emails with php script
Another is this:
Mail catcher

PHP mail() failing to send to internal addresses

I am trying to send out password reset links for when users forget their password to login to a system I am creating. The problem is, the smtp server is supposedly not configured on the server my system is hosted on. So whenever I try to use the php mail() function to send an email to an internal email address, the emails fail to send, but outside email address (tested with a gmail account), the emails go through. I believe this is because my server is sending directly out to the internet instead of passing through an internal smtp server to resolve where our domain emails should be sent. I was wondering if anyone knew how to configure this on an Xserve or if they knew how to specifically tell the php mail() function where to initially send the email. Any help or pointing in the right direction would be extremely helpful.
Thank you!
mail() doesn't send mail, it just hands things over to the local SMTP server. It does NOT reach out to the recipient's server to deliver the mail. In real world terms, mail() walks your letter down the street and drops it into the neighborhood mailbox. After that, it has absolutely nothing more to do with mail delivery.
Check your local SMTP server's logs to see why the local mails aren't being delivered. There should be a line or two saying why it's registered. Perhaps the local MTA (mail-transfer agent, aka the local "mail man") isn't configured properly.
You can control mail() with it's settings.
This might not solve your overall problem, but hopefully it's useful. This related answer has more information.
We just addressed this problem internally here. Hopefully this will help you as well.
Our environment:
Ubuntu 12.04 LTS
PHP 5.3.10
We could telnet into our SMTP server and send mail from our web server, so it wasn't a permissions issue. When attempting to mail externally, all works perfectly. When attempting to mail internally, silent failure.
Our PHP is using sendmail, which by default, attempts to relay mail to 127.0.0.1. Point this at your SMTP server by editing /etc/mail/sendmail.cf. Update the line from:
# "Smart" relay host (may be null)
DS
to
# "Smart" relay host (may be null)
DSyour.smtp.server.com
Restart sendmail and try sending yourself an email via PHP.
This is something that occurs on Parellels’ PLESK server administration software.
Find your ‘main.cf’ configuration file for PostFix, which for CentOS 6, is located at
/etc/postfix/main.cf
If you can’t find it, do a
which postfix
SSH command to at least see where Postfix is on your server.
Then, open the file up through a text editor, or in the Linux shell, and make these lines (should be at the end of the file, around line 677) :
virtual_mailbox_domains = $virtual_mailbox_maps, hash:/var/spool/postfix/plesk/virtual_domains
virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
virtual_mailbox_maps = hash:/var/spool/postfix/plesk/vmailbox
commented out like this :
#virtual_mailbox_domains = $virtual_mailbox_maps, hash:/var/spool/postfix/plesk/virtual_domains
#virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
#virtual_mailbox_maps = hash:/var/spool/postfix/plesk/vmailbox
Then, restart the Postfix service
sudo service postfix restart
Apache while your at it (can’t hurt), and voila! Your email address should be receiving those emails now. This also doesn’t affect any of your regular emails or anything else, either.

Categories