0

I have this PHP script that links in with a CRM, but the email doesn't send to the admin address; it only sends to the email address that the user puts in (their own email address). It does not send to the ADMIN EMAIL.

Here's the script. Any help would be great; I didn't write this and I haven't been in the job long!

<?php
$parameter = $_GET;
$query = http_build_query($parameter, '', '&');
$url = "CRM Address";
$url .= "?".$query; 

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: FROM EMAIL' . "\r\n" ;

$to = $_GET['Emailaddress'];
$subject = "Thank you";
$message = '

';

mail($to, $subject, $message, $headers);

$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$result = curl_exec($ch);
curl_close($ch);

$message2 = "";
foreach ($parameter as $k => $s){
    $message2 .= "<p>".$k." : ".$s."</p>";
}   
$to = "ADMIN EMAIL";
$subject2 = "Enquire";
mail($to2, $subject2, $message2, $headers);

if($result){
    header('Location:REDIRECT');
    }
?>
elixenide
  • 44,308
  • 16
  • 74
  • 100
Sam Kelham
  • 1,357
  • 4
  • 15
  • 28
  • 1
    upvoted because this question is valid, on-topic and question is really answerable. No need to down vote when you see a question with poor written code. A poor written question should be downvoted not poor written codes – Ceeee Feb 05 '16 at 02:52

1 Answers1

1

Look carefully at your script, especially this part:

$to = "ADMIN EMAIL";
$subject2 = "Enquire";
mail($to2, $subject2, $message2, $headers);

You set $to, but send the email to $to2. Change your script to

$to2 = "ADMIN EMAIL"; // fix the variable name
$subject2 = "Enquire";
mail($to2, $subject2, $message2, $headers);

This is a good illustration why you:

  1. Should use an IDE and a debugger.
  2. Should never just use scripts you got from the Internet if you don't understand them.
  3. Should use descriptive variable names, not $foo and $foo2.
elixenide
  • 44,308
  • 16
  • 74
  • 100