Sending form without mail client - forms

everubody! can you help me with my trouble? I'm trying to create form for filling resume. User should not use mail client to submit form. How can I realize this idea on javascript or PHP?

First: You need a server based script. Without any server interaction, no mail can be sent.
PHP has a mail() function and it works very well, if your server administrator enabled it.
Very simple example:
<?php
// The message
$message = "Line 1\nLine 2\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('caffeinated#example.com', 'My Subject', $message);
?>
If mail() is disabled, you need to connect a SMTP server with correct credentials and then you can send mails via this connection.
This function is implemented in the emailer module of phpBB2 e.g.
Good luck!

If the form as a file upload... You can just upload the cv to the webserver and then use your application to send an Email using your account.

Related

Intercept all emails sent from Xampp Mercury Mail Server

I have a Xampp Server that I use only in a development environment. In order to preview emails that would be sent from the live sites without actually sending them I would like to intercept all the emails sent from this server. I would like to be able to either send them all to a specific email or save them as files instead of sending them to whatever address they're set to go to. This way I can make sure they are correct without accidently sending emails during testing.
I found a similar question with an answer
here
but was unable to find a way to open any of the dialogs in the answer and so it didn't get me very far.
Thanks in advance for your help!
You can accomplish this using the sendmail configuration within your php.ini.
Create a file named smtp_catcher.php and the set the sendmail_path
sendmail_path = "php C:\path\to\file\smtp_catcher.php"
Then in your smtp_catcher.php add this block:
#!/Applications/XAMPP/xamppfiles/bin
<?php
# create a filename for the emlx file
list($ms, $time) = explode(' ', microtime());
$filename = dirname(__FILE__).'/'.date('Y-m-d h.i.s,', $time).substr($ms,2,3).'.emlx';
# write the email contents to the file
$email_contents = fopen('php://stdin', 'r');
$fstat = fstat($email_contents);
file_put_contents($filename, $fstat['size']."\n");
file_put_contents($filename, $email_contents, FILE_APPEND);
# open up the emlx file (using Apple Mail)
exec('open '.escapeshellarg($filename));
?>
Now I am not sure what extension you'll need to use to view the emails but this should catch all emails going out.
NOTE: make sure that php is in your window's environment PATH

Paypal IPN and mail() function

UPDATE: (2/29/12) Okay, so I've run into this same issue again for a different client on a completely different server and hosting company.
Again, having a script with just mail() sends out the email correctly with no issues. I then added code that is similar to what I have below and hooked it up with paypal IPN. Every time a new payment comes in, the IPN fires, the data gets saved to the db but the mail() function just doesn't work.
However, I ran into an interesting issue. I did a test IPN fire from paypal's sandbox with the same script and the email was sent out.
Is this an issue with paypals production IPN, perhaps the way that it posts data to the script?
Any information here would be extremely helpful since my current solution using cronjobs is sloppy.
END UPDATE
I have my paypal IPN listener configured properly since it writes all the information to the DB when a new payment comes in. Now I'm trying to setup a mail() function that sends me an email alert of a new payment.
I have done this before for another project but I can't for the life of my figure out why it's not working this time. I'm not getting any error's in the error_log and the rest of the script runs fine.
I've tested to make sure that the server actually does send mail with a standalone mail() script. I'm really lost and confused here.
Here's the code that I have:
mail('test#email.com', 'New Order', 'New Order', 'From: support#website.com');
define("_VALID_PHP", true);
require_once('../php/init.php');
$item_number = $_POST['item_number'];
$payment_gross = $_POST['payment_gross'];
$payment_status = $_POST['payment_status'];
$payer_email = $_POST['payer_email'];
$txn_id = $_POST['txn_id'];
if ($payment_status == 'Completed') {
$query = $db->query("SELECT price, id, uid FROM invoice WHERE md5='$item_number'");
$row = $db->fetch($query);
$iid = $row['id'];
$uid = $row['uid'];
if ($row['price'] == $payment_gross){
$invoiceUpdate['paid'] = 1;
$update = $db->update('invoice', $invoiceUpdate, "md5='$item_number'");
}
}
$data['iid'] = $iid;
$data['uid'] = $uid;
$data['payment_status'] = $payment_status;
$data['payer_email'] = $payer_email;
$data['payment_gross'] = $payment_gross;
$data['txn_id'] = $txn_id;
$db->insert('payment', $data);
Since your mail function returns true and your code looks correct, i think you should check the mail log because the problem might not be related to code. Try to send a mail and then check the mail log on the server...once i lost two days trying to figure out a similar problem and in the end the problem was that my mail was not accepted by other servers.
to finde your mail log you can do (from the shell):
updatedb;
locate mail.log
or
locate maillog
this assumes you are using linux, but the problem might as well exists also on windows
The code seems correct to me.
My advice:
Create a new PHP script and test the function there. Does it work?
Attempt PHP SMTP authentication with your mail server and send the email that way. Does it work? (You can use the PEAR Mail Package or any other valid SMTP class.)
If the above also fails then attempt to use the SMTP script with a custom service (e.g GMail) and check if emails are being sent. Here are the GMail SMTP parameters.
If all of the above fail, the problem is definitely with your hosting provider.
how about start off with a call to mail(), then gradually add the code that process $_POST to see when it breaks down? You should have sandbox testing with paypal to make this easier.
On a side note, you should send a verify message to Paypal server to check if the request is actually originated from Paypal, just for security.
Problem isn't in your PHP code, but on server-side. You might have full mail or your provider/your server has problems with SMTP server. Check configuration/Contact provider.
use phpmailer for mail tasks,
http://sourceforge.net/projects/phpmailer/
it will allow you to debug email problems easily.
If you've already tested the mail() function and it sends then I don't think it's anything to do with your mail settings. One word of advice, however, is that you need to be careful with the e-mail addresses you put into the mail() function. A lot of hosting providers nowadays prohibit you from sending e-mails from domains that aren't officially registered (so test#email.com would not work - it needs to be from your domain and it needs to be a valid e-mail address you've set up - it can't be a fake address at your real domain).
If it's still not working, try manually updating the php.ini settings:
<?php ini_set ( sendmail_from, "my_email#my_server.com" ); ?>
Once this is done try putting your mail() at the bottom of the script and feeding one variable to it. So an example might be:
mail('test#email.com', 'New Order', $iid, 'From: support#website.com');
If nothing's being sent, I suggest you re-evaluate your code to see if variables are filtering through your if statements. If all else fails, contact your hosting provider and describe to them your mail problems - it might be a server issue after all. If you're running it on localhost, then that's a different matter entirely (it's quite tricky setting up mail() on a localhost server).
Are you using this code on Windows or on Linux ?
The mail function should execute you must be linking the ipn to a duplicate ipn-handler php file or you did not properly save the changes to the server.
Otherwise it just does not make sense your code is crisp clear and if you send out the mail right on the top it should work.
Now if you are on Windows mail() usually isnt the best choice as Windows lacks default 'sendmail'.

php mail function only working on local server and not on remote server

just as the title I created a simple form in HTML
you can see it at http://thee-l.comuv.com/send.php this sends an email to me with the subject and body text specified I run this on localhost from Apache and I get in my inbox in less than a minute but I then upload it to the remote server the site and it does not email me at all
I have a gmail address so to make it easy I made an outgoing smtp server with smtp2go this was my first php-sent email, I was really happy and right away put it on the remote server and here we are
I am using 000webhost
here is my code
<?php
if ($_POST['submit']){
ini_set("SMTP", "smtp2go.com");
ini_set("smtp_port", 2525);
$to = "lsworkemail112#gmail.com";
$subj = $_POST['topic'];
$body = $_POST['message'];
$header = "From: lsworkemail112#gmail.com";
if (mail($to, $subj, $body, $header))
{
echo "Message sent successfully";
}
else
{
echo "Message sent unsuccessfully";
}
}
else
{
echo "<html>
<form method=\"post\" action=\"send.php\">
Topic: <br/><input type=\"text\" name=\"topic\"/><br/>
Message: <br/><textarea name=\"message\"></textarea><br/>
<input type=\"submit\" value=\"Send\" name=\"submit\"/>
</form>
</html>";
}
?>
I tried clicking on your link, but apparently your website is under review (possibly for mailing too much/suspected of spamming because of your testing?). Even then, linking to a .php page won't show us the code, since the server will execute it and send just the result to the browser. It's better if you copy/paste your code into the question.
Also, as #Computerish said, you may have just run into a limit on your host. How many times have you run your mail() code today?
Check your web hosting company's policies about outgoing mail. There may be a daily limit, a outright ban on it, or it may be an extra service you have to ask for. Almost all hosting companies do something to limit the use of the send() function to prevent spammers from taking advantage of their servers.

cakephp emails not working

my problem is:
in the controller I have:
var $components = array('Email');
the method to send emails looks like this:
function send_emails() {
$this->Email->from = 'Somebody <somebody#example.com>';
$this->Email->to = 'Somebody Else <myspamplace#centrum.cz>';
$this->Email->subject = 'Test';
$this->Email->send('Hello message body!');
}
I am using Cake 1.3 and running it on localhost with Apache 2.2.11 and PHP5. Do you guys have any idea why it doesn't work?
When I put
$this->Email->delivery = 'debug';
in the code, it displays the email info and it seems like everything is ok.
Do you have any ideas what can be the reason why it doesn't send email?
If you're developing on a remote server, i.e. a hosting server, then that should work as it'll pick up the default email.
As you're not, you have to give the mail component some email capability. You can do this by, for example, feeding in your gmail (or whatever) smtp details, i.e. server, login, password.
/* SMTP Options for GMAIL */
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'your_username#gmail.com',
'password'=>'your_gmail_password',
);
/* Set delivery method */
$this->Email->delivery = 'smtp';
See http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP
If you're not sure what credentials to use, look it up in your email provider's help or faq. Typically it can be found by searching for how to set up Outlook or Thunderbird.
Are you sending from a windows server? If so, have you properly setup your MTA in the php ini? Can you send mail using the mail() function?
If you are on windows and need an MTA, hMail is great for development, note that many hosts will reject mail from your local machine a spam so don't use on production without an MX record, domain keys etc.
You need an SMTP server to send email. If you are trying to send it from your localhost, two good alternatives are:
FreeSMTP: A Windows-based tool that lets your computer act like an SMTP Server
Gmail: You can use your Gmail address for testing purposes.
You need to follow the instructions to send email using CakePHP through SMTP. You could also modify your php.ini settings to reflect the new settings.
I had the same problem, I forgot to enable ssl on my xampp server, for that it is necessary just to add(or uncomment) extension=php_openssl.dll line in your php.ini file. Hope it helps.

How to send form contents anonymously via email

How do you send the content of a website form to an email address without disclosing the email address to the user.
Thanks!
PS: If at all possible, I would like this to be in HTML JavaScript Ok, anything I guess.
Not possible. You can however put a "fake" from header in the mail. You'll only risk it to end up in the junk folder.
HTML doesn't provide any functionality to send mails. You'll really need to do this in the server side. How exactly to do this depends on the server side programming language in question. In PHP for example, you have the mail() function. In Java you have the JavaMail API. And so on.
Regardless of the language used, you'll need a SMTP server as well. It's the one responsible for actually sending the mail. You can use the one from your ISP or a public email provider (Gmail, Yahoo, etc), but you'll be forced to use your account name in the from header. You can also register a domain with a mailbox and just register something like noreply#example.com and use this to send mails from.
Update: JavaScript can't send mails as well. Like HTML it's a client side language. You'll need to do it with a server side language. All JavaScript can do is to dump the entire page content back to the server side. jQuery may be useful in this:
$.post('/your-server-side-script-url', { body: $('body').html(); });
with (PHP targeted example)
$to = 'to#example.com';
$subject = 'Page contents';
$body = $_POST['body']
$headers = prepare_mail_headers();
mail($to, $subject, $body, $headers);
Update 2: if you actually want to hide the to header in the mail, then you'll need to use the bcc (Blind Carbon Copy) instead. This way the recipient addres(ses) will be undisclosed. Only the from, to, cc stays visible.
If you mean doing so on a client side, using mailto: link - you can not.
If you mean any way, yes - you submit the form contents back to your server, and have your back end script send the email.
You can do the form in HTML, but the posting will need to be done in a script. Even if you don't expose the email address, the script can be used to spam that email address. This is why you see captcha being used in such cases.
There are scripts available for most languages. Check to make sure their are no known security problems for the scripts. The original Matt's script in perl had problems, and the Perl community created a more secure version.