mailman022 Posted February 24, 2013 Share Posted February 24, 2013 Got this script on my webpage "www.******.com/mail.php". This is the script: <?php $to = "xxxxxx@gmail.com"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> And when I visit the page, an e-mail gets sent there. But I have a C# program and I want to change &to, &subject and &body in the PHP script. I have this at the moment: private void button2_Click(object sender, EventArgs e) { try { WebClient client = new WebClient(); client.DownloadString("http://xxxxxx/mail.php?to=" + "&to={xxxxxx@gmail.com}" + "&subject={Test}" + "&body={Test}"); client.Dispose(); } catch (Exception) { MessageBox.Show("An error occured loading the scripts, restart it again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } You see, I try to change &to={xxxxxx@gmail.com} and the others, but still the original message gets sent! The point of this code is, that the C# script will send an e-mail through mail.php. Please help, I would appreciate your time. Quote Link to comment https://forums.phpfreaks.com/topic/274894-simple-mail-script/ Share on other sites More sharing options...
Christian F. Posted February 25, 2013 Share Posted February 25, 2013 Seeing as you're always assigning values, and static values at that, in the PHP script. This is the expected behaviour. Same way that you'd expect this function to always give you "test", no matter what you called it with: private string function (string message) { message = 'test'; return message; } In other words: If you want to be able to change some of those values, you'll need to use the $_GET superglobal. Use isset () and empty () to check if the indices in question have been set. PS: If you do this, you need to secure your PHP script somehow. Otherwise anyone who has access to it (which is everyone, if it's available over the internet) will be able to use this to spam whomever they like. Quote Link to comment https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414760 Share on other sites More sharing options...
mailman022 Posted February 25, 2013 Author Share Posted February 25, 2013 I'm kind of new to this, I tried: <?php $to = $_GET["to"]; $subject = $_GET["subject"] $body = $_GET["message"] if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> and: try { WebClient client = new WebClient(); client.DownloadString("http://xxxx.nxxne.net/mail.php?" + "&to={xxxx@gmail.com}" + "&subject={Yxe}" + "&message={Test220}"); client.Dispose(); } catch (Exception) { MessageBox.Show("An error occured loading the scripts, restart the hack again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } But doesent work.. Quote Link to comment https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414837 Share on other sites More sharing options...
AyKay47 Posted February 25, 2013 Share Posted February 25, 2013 Define "doesn't work", are any errors received? This bit of code should put you on the right path: WebClient client = new WebClient(); string url = String.Format("http://www.domain.com/mail.php?to={0}&subject={1}&message={2}", "email@email.com", "recipient@email.com", "message"); client.DownloadString(url); // rest of code Quote Link to comment https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414845 Share on other sites More sharing options...
mailman022 Posted February 25, 2013 Author Share Posted February 25, 2013 (edited) Thanks for the code, I used that but still no e-mail gets sent like before. I think the error is in mail.php. When I go to mail.php page then: Parse error: syntax error, unexpected T_VARIABLE in /home/a8672447/public_html/mail.php on line 4 Error is on line 4? This is code: <?php $to = $_GET["to"]; $subject = $_GET["subject"] $body = $_GET["message"] if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Edited February 25, 2013 by mailman022 Quote Link to comment https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414858 Share on other sites More sharing options...
AyKay47 Posted February 25, 2013 Share Posted February 25, 2013 Place line terminating semi-colons on lines 3 and 4 Quote Link to comment https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414865 Share on other sites More sharing options...
mailman022 Posted February 25, 2013 Author Share Posted February 25, 2013 How could I be so stupid and miss that, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414871 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.